/*
##################
# Implementation #
##################
 
@constructor
@param {string} code - CSS color code.
185540
function Color( code ) {
    this.R = 0;
    this.G = 0;
    this.B = 0;
    this.A = 0;
    this.H = 0;
    this.S = 0;
    this.L = 0;

    if ( typeof code === 'string' ) {
        this.parse( code );
    }
}
972750
def create_color_method(color, code):
    

    def func(self, content=''):
        return self._apply_color(code, content)  # pylint: disable=protected-access

    setattr(Terminal, color, func)
1304923
function Color(color) {
    this._reset();
    if (typeof color === 'string') {
        this.parse(color);
    } else {
        var array;
        if (Array.isArray(color)) {
            array = color;
        } else if (typeof color === 'object' && Array.isArray(color.rgba)) {
            array = color.rgba;
        }
        if (array) {
            for (var i = 0; i < this.rgba.length; i++) {
                this.rgba[i] = array[i];
            }
        }
    }
}
892968
function(code)
  {
    var lineNumbers = [],
        lines = this.lines,
        firstLine = parseInt(this.opts.firstLine || 1),
        i,
        l
        ;

    for (i = 0, l = lines.length; i < l; i++)
      lineNumbers.push(i + firstLine);

    return lineNumbers;
  }
736148
function(fn) {
  var code = fn.toString();
  var match = code.match(/^(?:(?:function)?[\s]*\(([^)]*)\)|([^\=\(]+))/);
  var args = (match[1] || match[2]);
  if (typeof args === 'undefined') {
    return [];
  }
  return args.split(',').map(function(item) {
    return item.trim();
  }).filter(function(item) {
    return item;
  });
}
77877
function(code, lineNumbers)
        {
            var html = '',
                count = splitLines(code).length,
                firstLine = parseInt(this.getParam('first-line')),
                pad = this.getParam('pad-line-numbers')
                ;

            if (pad == true)
                pad = (firstLine + count - 1).toString().length;
            else if (isNaN(pad) == true)
                pad = 0;

            for (var i = 0; i < count; i++)
            {
                var lineNumber = lineNumbers ? lineNumbers[i] : firstLine + i,
                    code = lineNumber == 0 ? sh.config.space : padNumber(lineNumber, pad)
                    ;

                html += this.getLineHtml(i, lineNumber, code);
            }

            return html;
        }
1016369
function highlight(code) {
  return new Promise((resolve, reject) => {
    pygmentize({ lang: 'html', format: 'html' }, code, function (err, result) {
      if (err) {
        console.log(err);
        reject(err);
      } else {
        resolve(result.toString());
      };
    });
  });
}
336185
def set_code(self, code):
        

        for i, (_, style_code) in enumerate(self.styles):
            if code == style_code:
                self.SetSelection(i)
721902
function parse (code) {
  Object.keys(syntax).forEach((s) => {
    code = code.replace(syntax[s], (_, m) => {
      // ensure if the regex only matches part of the string that we keep the leftover
      let leftOver = _.replace(m, '')
      // encode the string and class
      let parsed = `{#${s}#${encode(m)}#}`

      if (s === 'function' && leftOver) {
        // we want to parse sub commands and the easiest way to do that is to
        // run over the leftOver portion of the function call with the same regex
        let startingParenthesis = leftOver.indexOf('(')
        let endingParenthesis = leftOver.lastIndexOf(')')
        let endingComma = leftOver.lastIndexOf(';')

        // since we don't want to create a new string for every operation
        // we can simply walk the string and replace the character that needs it
        let subFunction = leftOver.replace(/./g, (c, i) => {
          // we can define a waterfall case that only replaces the three positions with nothing
          // leaving the other characters in their place
          switch (i) {
            case startingParenthesis:
            case endingParenthesis:
            case endingComma:
              return ''
            default:
              return c
          }
        })
        leftOver = `(${parse(subFunction)})${endingComma > -1 ? ';' : ''}`
      }
      return parsed + leftOver
    })
  })
  return code
}
1020169
function align(code) {
  if (typeof code === 'string') {
    code = code.split('\n');
  }
  var match = code[code.length-1].match(/^(\s+)\}/);
  var regex = null;
  if (match && code[0].match(/^function/)) {
    regex = new RegExp("^" + match[1]);
    return code.map(function (line) {
      return line.replace(regex, "");
    });
  }
  return code;
}
1084377
function ( color, parse ) {
            var type = this.type( color, 'color.toHsl() : "' + color + '" ' + MSG_NOT_COLOR ),
                objColor;
    
            switch ( type ) {
                case 'rgb':
                case 'rgba':
                    objColor = this.rgbToHsl( color, true );
                    break;
                case 'hsl':
                    return parse? this.parseHsla( color ) : color;
                    break;
                case 'hsla':
                    objColor = this.parseHsla( color );
                    break;
                case 'keyword':
                    color = this.keyword( color, 'color.toHsl() : "' + color + '" ' + MSG_NOT_COLOR );
                case 'hex':
                    color = this.hexToRgb( color );
                    objColor = this.rgbToHsl( color, true );
                    break;
            }
    
            return parse? objColor : 'hsl(' + objColor.h + ', ' + objColor.s + '%, ' + objColor.l + '%)';
        }
539390
function(code){
        this.obj.should.have.property('statusCode');
        var status = this.obj.statusCode;

        this.assert(
            code == status
            , function(){ return 'expected response code of ' + code + ' ' + i(statusCodes[code])
                + ', but got ' + status + ' ' + i(statusCodes[status]) }
            , function(){ return 'expected to not respond with ' + code + ' ' + i(statusCodes[code]) });

        return this;
    }
343310
function css_beautify(source_text, options) {
    options = options || {};
    var indentSize = options.indent_size || 4;
    var indentCharacter = options.indent_char || ' ';

    // compatibility
    if (typeof indentSize == "string")
        indentSize = parseInt(indentSize);


    // tokenizer
    var whiteRe = /^\s+$/;
    var wordRe = /[\w$\-_]/;

    var pos = -1, ch;
    function next() {
        return ch = source_text.charAt(++pos)
    }
    function peek() {
        return source_text.charAt(pos+1)
    }
    function eatString(comma) {
        var start = pos;
        while(next()){
            if (ch=="\\"){
                next();
                next();
            } else if (ch == comma) {
                break;
            } else if (ch == "\n") {
                break;
            }
        }
        return source_text.substring(start, pos + 1);
    }

    function eatWhitespace() {
        var start = pos;
        while (whiteRe.test(peek()))
            pos++;
        return pos != start;
    }

    function skipWhitespace() {
        var start = pos;
        do{
        }while (whiteRe.test(next()))
        return pos != start + 1;
    }

    function eatComment() {
        var start = pos;
        next();
        while (next()) {
            if (ch == "*" && peek() == "/") {
                pos ++;
                break;
            }
        }

        return source_text.substring(start, pos + 1);
    }


    function lookBack(str) {
        return source_text.substring(pos-str.length, pos).toLowerCase() == str;
    }

    // printer
    var indentString = source_text.match(/^[\r\n]*[\t ]*/)[0];
    var singleIndent = Array(indentSize + 1).join(indentCharacter);
    var indentLevel = 0;
    function indent() {
        indentLevel++;
        indentString += singleIndent;
    }
    function outdent() {
        indentLevel--;
        indentString = indentString.slice(0, -indentSize);
    }

    var print = {}
    print["{"] = function(ch) {
        print.singleSpace();
        output.push(ch);
        print.newLine();
    }
    print["}"] = function(ch) {
        print.newLine();
        output.push(ch);
        print.newLine();
    }

    print.newLine = function(keepWhitespace) {
        if (!keepWhitespace)
            while (whiteRe.test(output[output.length - 1]))
                output.pop();

        if (output.length)
            output.push('\n');
        if (indentString)
            output.push(indentString);
    }
    print.singleSpace = function() {
        if (output.length && !whiteRe.test(output[output.length - 1]))
            output.push(' ');
    }
    var output = [];
    if (indentString)
        output.push(indentString);
    /*_____________________--------------------_____________________*/

    while(true) {
        var isAfterSpace = skipWhitespace();

        if (!ch)
            break;

        if (ch == '{') {
            indent();
            print["{"](ch);
        } else if (ch == '}') {
            outdent();
            print["}"](ch);
        } else if (ch == '"' || ch == '\'') {
            output.push(eatString(ch))
        } else if (ch == ';') {
            output.push(ch, '\n', indentString);
        } else if (ch == '/' && peek() == '*') { // comment
            print.newLine();
            output.push(eatComment(), "\n", indentString);
        } else if (ch == '(') { // may be a url
            if (lookBack("url")) {
              output.push(ch);
              eatWhitespace();
              if (next()) {
                if (ch != ')' && ch != '"' && ch != '\'')
                    output.push(eatString(')'));
                else
                    pos--;
              }
            } else {
              if (isAfterSpace)
                  print.singleSpace();
              output.push(ch);
              eatWhitespace();
            }
        } else if (ch == ')') {
            output.push(ch);
        } else if (ch == ',') {
            eatWhitespace();
            output.push(ch);
            print.singleSpace();
        } else if (ch == ']') {
            output.push(ch);
        }  else if (ch == '[' || ch == '=') { // no whitespace before or after
            eatWhitespace();
            output.push(ch);
        } else {
            if (isAfterSpace)
                print.singleSpace();

            output.push(ch);
        }
    }


    var sweetCode = output.join('').replace(/[\n ]+$/, '');
    return sweetCode;
}
278550
function prepareColors(colors) {
    Object.keys(colors).forEach(function (color) {
        var code = colors[color],
            replaced = replaceColors(code, colors);

        if (replaced !== code) {
            colors[color] = replaced;
        }
    });
}
638780
function beautifyCode(str) {
    var beautifulStr = str;

    try {
        beautifulStr = (0, _jsBeautify.html)(str, beautifySettings);
    } catch (err) {
        console.error('Beautify error:', err.message);
    }

    return beautifulStr;
}
1053852
function outputClassBody( code ) {
    try {
        let out = '';
        if ( code.that ) out += "        const that = this;\n";
        if ( code.pm ) out += "        const pm = PM(this);\n";
        out += generate( code.section.attribs.define, "Create attributes", "        " );
        out += generate( code.section.elements.define, "Create elements", "        " );
        out += generate( code.section.events, "Events", "        " );
        out += arrayToCodeWithNewLine( code.generateLinks(), "        " );
        out += generate( code.section.ons, "On attribute changed", "        " );
        out += generate( code.section.elements.init, "Initialize elements", "        " );
        out += generate( code.section.attribs.init, "Initialize attributes", "        " );
        if ( code.section.init ) {
            out += "        // Initialization.\n";
            out += `        CODE_BEHIND.${code.section.init}.call( this );\n`;
        }
        out += "        $.addClass(this, 'view', 'custom');\n";
        return out;
    } catch ( ex ) {
        bubble( ex, "outputClassBody" );
        return null;
    }
}
341524
function compile(code, filename, options) {
  options = defaults(options || {}, {
    embedSourceMaps: true,
    bareModule: false,
    color: false
  });
  if (arguments.length !== compile.length) {
    throw new Error("incorrect argument count to compile");
  }
  var result = parse(ensureNewline(code));
  if (!result.status) {
    var expectations = uniq(result.expected);
    var data = "expected one of " + expectations.join(", ");
    var index = Math.min(result.index, code.length - 1);
    var oopsyInput = {index: index, data: data};
    var oopsies =
      OopsyData.fromIndices(code, [oopsyInput], {color: options.color});
    return {
      parsed: false,
      result: {
        expectations: expectations,
        oopsy: oopsies[0]
      }
    };
  }
  var squiggleAst = result.value;
  squiggleAst.bareModule = options.bareModule;
  var warnings = lint(squiggleAst);
  var contextualWarnings =
    OopsyData.fromLocations(code, warnings, {color: options.color});
  var esAst = transformAst(squiggleAst);
  var mangledAst = SHOULD_MANGLE ?
    esmangle.optimize(esAst) :
    esAst;
  var optimizedAst = SHOULD_OPTIMIZE ?
    optimize(mangledAst) :
    mangledAst;
  var stuff = generateCodeAndSourceMap(
    optimizedAst, filename, code);
  var js = ensureNewline(stuff.code);
  var sourceMap = stuff.map.toString();
  if (options.embedSourceMaps) {
    js = addSourceMapUrl(js, sourceMap);
  }
  return {
    parsed: true,
    warnings: contextualWarnings,
    sourceMap: sourceMap,
    code: js
  };
}