Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/modules / ___dist / view-container / styles / templateHandler.js
Size: Mime:
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.templateHandler = templateHandler;
exports.default = void 0;

var _config = require("../config");

// import theme from 'client/styles/theme'

/**
 * @tutorial http://2ality.com/2015/01/template-strings-html.html
 * @tutorial https://babeljs.io/repl-old/#?babili=false&evaluate=false&lineWrap=false&presets=env&targets=&browsers=&builtIns=true&debug=false&build=&circleciRepo=&code_lz=PQKhCgAIUgBAHAhgJ0QW0gbwILNQTwB4BlAF2QEsA7AcwD4BfSAGwtIFNVnj2BjUigHsqAZ0hQYCFOiwB-XARLlqNSAB9IAMQCuVfkKrrICxPkaRqHZPEHNEA4cW0AjEQNLaHo8dGDgAZrr6wpAcaPB2HAASiFQAJsycABSsVojcfF4iADSQAHQFlpw2kQZOru6eBiIAlFhQkHHszto0NJziDcDAkACqIuyQqADuLGyc6ZADwaIAXJDDg3HCgJgEpAuxpF09zoi8ANYidiIAFuxiSQA6huykvHl1pIKQzoNF1si37HENiesjkAAvGM0hkZiI8iNwL9bkNztpmOtgQByZHQyAWKhWEr2MouNxsKrCCH-QTIACiexOSSSInxlS8uQodUBdHqGIx3UgACVbpR2AA3QakM4gibMKaZAyQeCfXjfFQNTk9EWDXjaPDsLFTemErxKliw1LizRkgDCGs-WPKBI8XiBQ0QwwA2hQALrojlcgCShlVkHYAA90BF2Lk0Ih4Ek6p8PMhvLFICgCLMDT7_DqKnrpRQxInk6ZIElYnFIFRBOtEFNlLQatk0z1FqENYY2Jinknq5RaAaKBmkiZ8Hlc4Pabq7QYanVMAaMXSsxOQsD57aiVQ8gArQTUJKomoGhiejF9oukfDwdiCDMrhnSwH3yDIwJ6LzI6ezzOr-3L8dr3fOQRBHwRA3wPI9IHTUJRRvbMQlzGU5W-b4XnwTtlmYOxkCmCgaCoesOQgxtBnOXhI0GEQL14ChJl4E5pH4TgxGoCwtgIrkTxSNg8i1OIRAAdTYalkQAEjfd82J6DFUgdVI8iOCh5SSAAGXIAFoAEZ9wkyBDwIz46URSAAGpgWNLhTWQC1NWtX99T0-FDJMz9b2EBoGC0wjIAAFUQfY1RQQYrxYRA3DFLhJRmbYiwAOUFDp_EQChmByF4-EQbQBiTG5wjPUJ2HCSJyJrGgotlQQ4m0eUxGEQYzMmaZGSygMctQtxuxoDz9IRdYnJGZ0RjyRJaBFSBVMgdS3U8gd9waWMWzhAytkPcAwgiex2BieJEiwgADBpuJOdkOQA5AmmQeZ1KU-BAymWwKFLE4K3gah9gAbgNXhbDJeZhMwVU0EGVkoPywYADJQeBgHdJ08A9qAA&isEnvPresetTabExpanded=true&isPresetsTabExpanded=true&isSettingsTabExpanded=true&prettier=true&showSidebar=true&version=6.26.0
 * @see http://exploringjs.com/es6/ch_template-literals.html#sec_implementing-tag-functions
 * @see https://www.styled-components.com/docs/advanced#tagged-template-literals
 *
 * @api https://tc39.github.io/proposal-template-literal-revision/
 *
 * @param {Array<String>} literalSections
 * @param {?Array<String | Function | Array>} interpolationSubstitutions
 * @return {String} interpolated/rendered template
 *
 * flatten(styleTemplateStrings).join('\n')
 */
function templateHandler(literalSections, ...interpolationSubstitutions) {
  // Use raw literal sections: we don’t want
  // backslashes (\n etc.) to be interpreted
  const raw = literalSections.raw || [literalSections];
  let result = '';
  /**
   * @todo move this into a smaller more eagerly optimized function
   */

  interpolationSubstitutions.forEach((substitution, i) => {
    // Retrieve the literal section preceding
    // the current substitution
    const literalForCurrentSubstitution = raw[i]; // In the example, map() returns an array:
    // If substitution is an array (and not a string),
    // we turn it into a string

    if (Array.isArray(substitution)) {
      substitution = substitution.join('');
    }

    if (typeof substitution === 'function') {
      // if it is a style `blocks`
      if (typeof substitution[Symbol.toPrimitive] === 'function' && typeof substitution.styles === 'function') {
        substitution = substitution.styles;
      } else {
        substitution = substitution.call(this, _config.config.get('theme'));
      }
    } // if (substitution.includes('$')) {
    //   substitution = substitution.split('\n').map((line, index) => {
    //     // from $ (anything) until end of line
    //     return line.replace(/\$(.*)$/, function(searchValue, replaceValue) {
    //       return styled[searchValue]
    //     })
    //   })
    // }
    // If the substitution is preceded by a dollar sign,
    // @TODO @james can interpolate anything in here
    // if (literalForCurrentSubstitution.endsWith('$')) {
    //   literalForCurrentSubstitution = literalForCurrentSubstitution.slice(0, -1)
    // }


    result += literalForCurrentSubstitution;
    result += substitution;
  }); // Take care of last literal section
  // (Never fails, because an empty template string
  // produces one literal section, an empty string)
  // @example (A)

  result += raw[raw.length - 1];
  return result;
}
/**
 * @todo move out?
 */


templateHandler.setTheme = function (replacementTheme) {
  templateHandler.theme = replacementTheme;

  _config.config.set('theme', replacementTheme);

  return templateHandler;
};

const theme = _config.config.get('theme');

templateHandler.setTheme(theme);
var _default = templateHandler;
exports.default = _default;