Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

less-openui5

SAP463.2kApache-2.00.11.6

Build OpenUI5 themes with Less.js

openui5, sapui5, ui5, less, less.js, theme

readme

OpenUI5

REUSE status Build Status NPM Version

less-openui5

Build OpenUI5 themes with Less.js.

Install

npm install less-openui5

Usage

var lessOpenUI5 = require('less-openui5');

// Create a builder instance
var builder = new lessOpenUI5.Builder();

// Build a theme
builder.build({
  lessInput: '@var: #ffffff; .class { color: @var; float: left }'
})
.then(function(result) {

  console.log(result.css); // => regular css
  /*
  .class {
   color: #ffffff;
   float: left;
  }
  */

  console.log(result.cssRtl); // => mirrored css for right-to-left support
  /*
  .class {
    color: #ffffff;
    float: right;
  }
  */

  console.log(result.variables); // => less variables with their values (only global ones)
  /*
  { var: "#ffffff" }
  */

  console.log(result.imports); // => paths to files imported via @import directives
  /*
  []
  */

  // Clear builder cache when finished to cleanup memory
  builder.clearCache();

});

API

new Builder([options])

Creates a new Builder instance.

It caches build results to only rebuild a theme when related files have been changed.
This is mainly relevant when building themes as part of a server middleware like connect-openui5.

options

fs

Type: Node.js fs interface

By default, all file system access is done via the standard Node.js file system ("fs"). With this option an alternative file system can be passed and will be used for all file system operations.

.build(options)

Returns a Promise resolving with a result object.

options

lessInput

Required (either lessInput or lessInputPath, not both)
Type: string

Input less content.

lessInputPath

Required (either lessInput or lessInputPath, not both)
Type: string

Path to input less file.
When rootPaths is given this must be a relative path inside one of the provided rootPaths, otherwise just a regular filesystem path.

rtl

Type: boolean
Default: true

Create mirrored css for right-to-left support.

cssVariables

Type boolean
Default: false

Create files for experimental CSS Variables support (cssSkeleton, cssSkeletonRtl, cssVariablesSource, cssVariables).

rootPaths

Type: array of string

Root paths to use for import directives.

This option differs from the less compiler.paths option.
It is useful if less files are located in separate folders but referenced as they would all be in one.

Example
rootPaths: [ './lib1', './lib2' ]

Folder structure

lib1
 my
  themes
   foo
    foo.less
lib2
 my
  themes
   bar
    bar.less

lib2/my/themes/bar/bar.less

@import "../foo/foo.less"; /* lib1/my/themes/foo/foo.less will be imported */
parser

Type: object

Options for the less parser (less.Parser).

Note

  • Default of relativeUrls option is changed from false to true.
  • Option javascriptEnabled has been removed. JavaScript is always disabled and cannot be enabled.
compiler

Type object

Options for the less compiler (tree.toCss).

Note: The options sourceMap and cleancss are not supported. An exception will be thrown when used.

library.name

Type string

Dot-separated name of the corresponding library.
It will be used to inline the variables JSON as data-uri which can be retrieved at runtime.

scope

Type object

Scope options to be set when not using a .theming file. The available settings are:

  • selector
  • embeddedFilePath
  • embeddedCompareFilePath
  • baseFilePath

Those settings correspond to the aScopes property of the .theming file. When using this options all four settings have to be set.

Example:

scope: {
  selector: "scopeSelector",
  embeddedFilePath: "src/themes/theme_to_be_embedded.less",
  embeddedCompareFilePath: "src/themes/basetheme_to_compare_embedded_theme_to.less",
  baseFilePath: "src/themes/basetheme_to_compare_embedded_theme_to.less"
}

result

css

Type: string

Regular css output.

cssRtl

Type: string

Mirrored css for right-to-left support (if rtl option was enabled).

variables

Type: object

Key-value map of global less variables (without @ prefix) defined by files within the same folder as the input file. This excludes variables imported from a different path, as those are usually shared across multiple themes.

allVariables

Type: object

Key-value map of all global less variables (without @ prefix).

imports

Type: array

Paths to files imported via import directives.

cssSkeleton

Type: string
Only available when options.cssVariables is set to true

CSS with references to CSS Variables.

cssSkeletonRtl

Type: string
Only available when options.cssVariables and options.rtl are set to true

Mirrored (right-to-left) CSS with references to CSS Variables (if rtl option was enabled).

cssVariablesSource

Type: string
Only available when options.cssVariables is set to true

Source file used to compile the cssVariables output.

cssVariables

Type: string
Only available when options.cssVariables is set to true

Definition of CSS Variables based on LESS variables.

.clearCache()

Clears all cached build results.
Use this method to prevent high memory consumption when building many themes within the same process.

Contributing

See CONTRIBUTING.md.

Release History

See CHANGELOG.md.

changelog

Changelog

All notable changes to this project will be documented in this file.
This project adheres to Semantic Versioning.

A list of unreleased changes can be found here.

v0.11.6 - 2023-01-23

Bug Fixes

  • Switch to maintained fork of "css" package (#272) 0bb592d

v0.11.5 - 2022-12-12

Bug Fixes

  • Revert "Switch to maintained fork of "css" package" (#261) 3b6c459

v0.11.4 - 2022-12-01

Bug Fixes

v0.11.3 - 2022-11-30

Bug Fixes

  • Switch to maintained fork of "css" package 0abe66a

v0.11.2 - 2021-06-28

Bug Fixes

  • CSS Variables: Fix variable handling / relative urls (#172) 6ace17f

v0.11.1 - 2021-03-17

Bug Fixes

  • Variables: Include variables defined in sub-directories (#160) 5568cd6

v0.11.0 - 2021-03-10

Breaking Changes

  • Only rewrite image paths for RTL-variant when files exist (#162) 88e7a74

BREAKING CHANGE

This affects the output of the rtl (right-to-left) variant that is created by applying several mechanisms to create a mirrored variant of the CSS to be used in locales that use a right to left text direction.

One aspect is adopting urls which contain an img folder in the path. Before this change, all urls have been changed to use a img-RTL folder instead. This allows mirrored images to be used, but it also requires an images to be available on that path even when the original image should be used (e.g. for a logo).

With this change:

  • Urls are only adopted in case an img-RTL variant of that file exists
  • Urls with a protocol (http/https/data/...) or starting with a slash (/) are not adopted anymore

v0.10.0 - 2021-01-29

Breaking Changes

  • Security: Disable JavaScript execution in Less.js c0d3a85

BREAKING CHANGE

Parser option javascriptEnabled has been removed. JavaScript is always disabled and cannot be enabled.

v0.9.0 - 2020-11-06

Breaking Changes

  • Remove support for import over http(s) e4a1c86
  • Require Node.js >= 10 47f244e

BREAKING CHANGE

Import over http(s) is not supported anymore. Use the Builder 'fs' option to provide an interface that also handles http(s) resources.

Support for older Node.js releases has been dropped. Only Node.js v10 or higher is supported.

v0.8.7 - 2020-06-26

Bug Fixes

  • Error handling for missing scoping files c7513a1

v0.8.6 - 2020-02-24

Bug Fixes

  • CSS var assignment only for less to less vars (#116) 2e9560d

v0.8.5 - 2020-02-21

Features

  • Keep linking of less vars for css vars (#115) 3f99e9d

v0.8.4 - 2020-02-10

Features

  • Add experimental CSS variables and skeleton build (#108) e6d8503

v0.8.3 - 2020-01-07

Bug Fixes

v0.8.2 - 2019-12-16

Bug Fixes

  • Support absolute import paths in less files (#107) 266b06d

v0.8.1 - 2019-12-03

Bug Fixes

v0.8.0 - 2019-11-18

Breaking Changes

  • Remove support for 'sourceMap' / 'cleancss' options 3f234c8

Bug Fixes

  • Apply less.js fix for import race condition 694f6c4

0.7.0 - 2019-10-30

Breaking Changes

  • Drop support for Node.js < 8.5 810962c

Bug Fixes

0.6.0 - 2018-09-10

Breaking changes

  • Drop unsupported Node.js versions. Now requires >= 6 #45

Fixes

  • Again, fix inline theme parameters encoding for '#' #48

All changes

0.5.4...0.6.0

0.5.4 - 2018-07-04

Fixes

  • Revert "Fix inline theme parameters encoding for '#'" #26

All changes

0.5.3...0.5.4

0.5.3 - 2018-05-18

Fixes

  • Fix less error propagation #22
  • Fix inline theme parameters encoding for '#' #23

All changes

0.5.2...0.5.3

0.5.2 - 2018-03-26

Fixes

  • Fix reduced set of variables #20

All changes

0.5.1...0.5.2

0.5.1 - 2018-03-12

Fixes

  • Changed paths in variable collector to posix variant #19

All changes

0.5.0...0.5.1

0.5.0 - 2018-02-09

Features

  • Reduce collected variables to only add relevant ones #18

All changes

0.4.0...0.5.0

0.4.0 - 2017-12-13

Features

  • Add scope option #16
  • Add custom fs option #17

All changes

0.3.1...0.4.0

0.3.1 - 2017-03-28

Fixes

  • Performance workaround: Handle properties directly added to String proto #12

All changes

0.3.0...0.3.1

0.3.0 - 2017-03-23

Breaking changes

  • Drop support for Node.js v0.10 #5
  • Replace static build function with Builder class to enable caching of build results #10
  • Refactor options to also include input LESS string #6

Features

  • Added "lessInputPath" option to provide a path relative to the "rootPaths" #10
  • Added diffing and scoping to support Belize contrast areas #10
  • Analyze .theming files as theme scope indicators #10

All changes

0.2.0...0.3.0

0.2.0 - 2016-03-15

Breaking changes

  • Set default of parser option relativeUrls to true 00d892b

Features

  • Include inline theming parameters 4fa91b9

All changes

0.1.3...0.2.0