All files / src/app/common/style-with-less.decorator style-with-less.ts

80.77% Statements 21/26
88.89% Branches 16/18
83.33% Functions 5/6
80.77% Lines 21/26
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54      1x   1x 1x   1x 1x 1x                             4x 4x 4x 7x 3x   4x     4x 4x 3x 3x 3x 3x     4x       4x 4x            
// Ref: http://myrighttocode.org/blog/typescript/angular2/decorators/angular2-custom-decorators
 
'use strict';
export function StyleWithLess(lessStyles) {
 
  const __ref__ = window['Reflect'],
    flatStyles = parseLessStyles('', lessStyles);
 
  return function (target) {
    const metaInformation = __ref__.getOwnMetadata('annotations', target);
    Iif (metaInformation) {
      parseMeta(metaInformation);
    }
  };
 
  // Parse metadata logic
  function parseMeta(metaInformation) {
    const metaInformation_1 = metaInformation;
    for (let _i = 0; _i < metaInformation_1.length; _i++) {
      const metadata = metaInformation_1[_i];
      metadata.styles = [flatStyles];
    }
  }
 
  function parseLessStyles(prefix, def) {
    const queue = [];
    let result = (prefix && prefix !== '') ? prefix + ' { ' : '';
    for (const key in def) {
      if (typeof def[key] === 'object') {
        queue.push({ key: key, value: def[key] });
      } else {
        result += toDashCase(key) + ':' + def[key] + ';';
      }
    }
    result += (prefix && prefix !== '') ? '}' : '';
    if (queue && queue.length > 0) {
      const queue_1 = queue;
      for (let _i = 0; _i < queue_1.length; _i++) {
        const sub = queue_1[_i];
        result += parseLessStyles(prefix + (sub.key[0] === '&' ? sub.key.substr(1) : ' ' + sub.key), sub.value);
      }
    }
    return result;
  }
 
  function toDashCase(str) {
    return str.replace(/([A-Z])/g, function ($1) {
      return '-' + $1.toLowerCase();
    });
  }
 
}
// # sourceMappingURL=StyleWithLess.js.map