/** @typedef {string | string[]} GlobPattern */ export type GlobPattern = string | string[]; /** @typedef {Promise | string} MinifyResult */ type MinifyResult = Promise | string; /** * @typedef {(shader: string) => MinifyResult} MinifyCallback * * @param {string} shader Shader code with included chunks * * @returns {MinifyResult} Minified shader's source code */ type MinifyCallback = (shader: string) => MinifyResult; /** * @default false * @typedef {MinifyCallback | boolean} Minify * * @description A boolean value or a custom * callback function to optimize output shader length */ type Minify = MinifyCallback | boolean; /** * @typedef {Object} LoadingOptions * @description Shader loading config object * * @property {string} defaultExtension Shader suffix to use when no extension is specified * @property {boolean} warnDuplicatedImports Warn if the same chunk was imported multiple times * @property {boolean} removeDuplicatedImports Automatically remove an already imported chunk * @property {string} importKeyword Keyword used to import shader chunks * @property {Minify} minify Minify output shader code * @property {string} root Directory for root imports */ export type LoadingOptions = { warnDuplicatedImports: boolean; removeDuplicatedImports: boolean; defaultExtension: string; importKeyword: string; minify: Minify; root: string; }; /** * @since 0.2.0 * @extends LoadingOptions * @typedef {Object} PluginOptions * @description Plugin config object * * @property {GlobPattern} include Glob pattern(s array) to import * @property {GlobPattern} exclude Glob pattern(s array) to ignore * @property {boolean} watch Recompile shader on change * * @default { * include: Object.freeze([ * '**\/*.glsl', '**\/*.wgsl', * '**\/*.vert', '**\/*.frag', * '**\/*.vs', '**\/*.fs' * ]), * exclude: undefined, * defaultExtension: 'glsl', * warnDuplicatedImports: true, * removeDuplicatedImports: false, * importKeyword: '#include', * minify: false, * watch: true, * root: '/' * } */ export type PluginOptions = Partial & { include?: GlobPattern; exclude?: GlobPattern; watch?: boolean; }; /** * @since 1.1.2 * @typedef {Object} LoadingOutput * * @returns {LoadingOutput} Loaded, parsed (and minified) * shader output and Map of shaders that import other chunks * * @property {Map} dependentChunks Map of shaders that import other chunks * @property {string} outputShader Shader file with included chunks */ export type LoadingOutput = { dependentChunks: Map; outputShader: string; };