From 52101239773d598c3fdc94b6b6a778ad6d3db147 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Thu, 10 Mar 2022 17:19:04 +0530 Subject: [PATCH] Document options --- postcss/css-compile-variables.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/postcss/css-compile-variables.js b/postcss/css-compile-variables.js index 732ed8b3..38f5c471 100644 --- a/postcss/css-compile-variables.js +++ b/postcss/css-compile-variables.js @@ -76,13 +76,21 @@ function addResolvedVariablesToRootSelector(root, variables, { Rule, Declaration root.append(newRule); } -/* * - * @type {import('postcss').PluginCreator} +/** + * @callback derive + * @param {string} value - The base value on which an operation is applied + * @param {string} operation - The operation to be applied (eg: darker, lighter...) + * @param {string} argument - The argument for this operation + */ +/** + * + * @param {Object} opts - Options for the plugin + * @param {Object} opts.variables - An object with records of the form: {base_variable_name: value} + * @param {derive} opts.derive - The callback which contains the logic for resolving derived variables */ module.exports = (opts = {}) => { aliasMap = new Map(); resolvedMap = new Map(); - const {variables} = opts; return { postcssPlugin: "postcss-compile-variables", @@ -94,7 +102,7 @@ module.exports = (opts = {}) => { */ root.walkDecls(decl => extractAlias(decl)); root.walkDecls(decl => resolveDerivedVariable(decl, opts)); - addResolvedVariablesToRootSelector(root, variables, { Rule, Declaration }); + addResolvedVariablesToRootSelector(root, opts.variables, { Rule, Declaration }); }, }; };