Skip to content

Commit 77e0ebb

Browse files
committed
[INTERNAL] Implement inlineCssVariables option
1 parent ddf0160 commit 77e0ebb

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

lib/index.js

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -281,40 +281,56 @@ Builder.prototype.build = function(options) {
281281
}
282282

283283
// also compile css-variables version if requested
284-
if (options.cssVariables) {
284+
if (options.cssVariables || options.inlineCssVariables) {
285285
// parse the content again to have a clean tree
286286
const cssVariablesSkeletonTree = await parseContent(config.content);
287287

288288
// generate the skeleton-css and the less-variables
289289
const CSSVariablesCollectorPlugin = require("./plugin/css-variables-collector");
290290
const oCSSVariablesCollector = new CSSVariablesCollectorPlugin(config);
291-
result.cssSkeleton = cssVariablesSkeletonTree.toCSS(Object.assign({}, options.compiler, {
291+
292+
const cssSkeleton = cssVariablesSkeletonTree.toCSS(Object.assign({}, options.compiler, {
292293
plugins: [oCSSVariablesCollector]
293294
}));
294-
result.cssVariablesSource = oCSSVariablesCollector.toLessVariables();
295+
const cssVariablesSource = oCSSVariablesCollector.toLessVariables();
296+
297+
let cssSkeletonRtl;
295298
if (oRTL) {
296299
const oCSSVariablesCollectorRTL = new CSSVariablesCollectorPlugin(config);
297-
result.cssSkeletonRtl = cssVariablesSkeletonTree.toCSS(Object.assign({}, options.compiler, {
300+
cssSkeletonRtl = cssVariablesSkeletonTree.toCSS(Object.assign({}, options.compiler, {
298301
plugins: [oCSSVariablesCollectorRTL, oRTL]
299302
}));
300303
}
301304

302305
// generate the css-variables content out of the less-variables
303-
const cssVariablesTree = await parseContent(result.cssVariablesSource);
306+
const cssVariablesTree = await parseContent(cssVariablesSource);
304307
const CSSVariablesPointerPlugin = require("./plugin/css-variables-pointer");
305-
result.cssVariables = cssVariablesTree.toCSS(Object.assign({}, options.compiler, {
308+
const cssVariables = cssVariablesTree.toCSS(Object.assign({}, options.compiler, {
306309
plugins: [new CSSVariablesPointerPlugin()]
307310
}));
311+
312+
result.cssVariables = cssVariables;
313+
314+
// Only add additional CSS Variables content if requested
315+
if (options.cssVariables) {
316+
result.cssSkeleton = cssSkeleton;
317+
if (oRTL) {
318+
result.cssSkeletonRtl = cssSkeletonRtl;
319+
}
320+
result.cssVariablesSource = cssVariablesSource;
321+
}
308322
}
309323

310324
return result;
311325
}
312326

313327
async function addInlineParameters(result) {
314-
if (
315-
options.inlineThemingParameters === true &&
316-
typeof options.library === "object" && typeof options.library.name === "string"
317-
) {
328+
// Inline parameters can only be added when the library name is known
329+
if (typeof options.library !== "object" || typeof options.library.name !== "string") {
330+
return result;
331+
}
332+
333+
if (options.inlineThemingParameters === true) {
318334
const parameters = JSON.stringify(result.variables);
319335

320336
// properly escape the parameters to be part of a data-uri
@@ -339,8 +355,11 @@ Builder.prototype.build = function(options) {
339355
}
340356
}
341357

342-
if (options.inlineCssVariables) {
343-
// TODO
358+
if (options.inlineCssVariables === true) {
359+
result.css = result.cssVariables + result.css;
360+
if (options.rtl) {
361+
result.cssRtl = result.cssVariables + result.cssRtl;
362+
}
344363
}
345364

346365
return result;

0 commit comments

Comments
 (0)