<commit_before># Copyright 2013 <NAME> <<EMAIL>>,
# sponsored by <NAME>.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http:#www.gnu.org/licenses/>.

OldValue = require('../old-value')
Value    = require('../value')
utils    = require('../utils')

isDirection = new RegExp('(top|left|right|bottom)', 'gi')

class Gradient extends Value
  @names = ['linear-gradient', 'repeating-linear-gradient',
            'radial-gradient', 'repeating-radial-gradient']

  @starts  = new RegExp('(^|\\s*)' + @names.join('|'), 'i')
  @regexps = { }
  for i in @names
    @regexps[i] = new RegExp('(^|\\s|,)' + i + '\\((.+)\\)', 'gi')

  # Cache regexp to parse params
  constructor: (@name, @prefixes) ->
    @regexp      = Gradient.regexps[@name]

  # Change degrees for webkit prefix
  addPrefix: (prefix, string) ->
    string.replace @regexp, (all, before, args) =>
      prefixedDecls = []

      for decl in @splitDecls(all)
        prefixedDecls.push decl.replace @regexp, (all, before, args) =>
          params = @splitParams(args)
          params = @newDirection(params)

          if prefix == '-webkit- old'
            return all if @name != 'linear-gradient'
            return all if params[0] and params[0].indexOf('deg') != -1
            return all if args.indexOf('-corner') != -1
            return all if args.indexOf('-side')   != -1

            params = @oldDirection(params)
            params = @colorStops(params)

            '-webkit-gradient(linear, ' + params.join(', ') + ')'
          else
            if params.length > 0
              if params[0][0..2] == 'to '
                params[0] = @fixDirection(params[0])
              else if params[0].indexOf('deg') != -1
                params[0] = @fixAngle(params[0])
              else if params[0].indexOf(' at ') != -1
                @fixRadial(params)
            before + prefix + @name + '(' + params.join(', ') + ')'

      prefixedDecls.join(',')

  # Direction to replace
  directions:
    top:    'bottom'
    left:   'right'
    bottom: 'top'
    right:  'left'

  # Direction to replace
  oldDirections:
    'top':    'bottom left, top left'
    'left':   'top right, top left'
    'bottom': 'top left, bottom left'
    'right':  'top left, top right'

    'top right':    'bottom left, top right'
    'top left':     'bottom right, top left'
    'bottom right': 'top left, bottom right'
    'bottom left':  'top right, bottom left'

  # Split gradients in background value
  splitDecls: (decl) ->
    decls       = []
    chunks      = decl.split(',')
    currentDecl = []
    for i in chunks
      # chunks starts with gradient declaration<commit_msg>Fixing direction order for old style webkit-gradient<commit_after># Copyright 2013 <NAME> <<EMAIL>>,
# sponsored by <NAME>.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http:#www.gnu.org/licenses/>.

OldValue = require('../old-value')
Value    = require('../value')
utils    = require('../utils')

isDirection = new RegExp('(top|left|right|bottom)', 'gi')

class Gradient extends Value
  @names = ['linear-gradient', 'repeating-linear-gradient',
            'radial-gradient', 'repeating-radial-gradient']

  @starts  = new RegExp('(^|\\s*)' + @names.join('|'), 'i')
  @regexps = { }
  for i in @names
    @regexps[i] = new RegExp('(^|\\s|,)' + i + '\\((.+)\\)', 'gi')

  # Cache regexp to parse params
  constructor: (@name, @prefixes) ->
    @regexp      = Gradient.regexps[@name]

  # Change degrees for webkit prefix
  addPrefix: (prefix, string) ->
    string.replace @regexp, (all, before, args) =>
      prefixedDecls = []

      for decl in @splitDecls(all)
        prefixedDecls.push decl.replace @regexp, (all, before, args) =>
          params = @splitParams(args)
          params = @newDirection(params)

          if prefix == '-webkit- old'
            return all if @name != 'linear-gradient'
            return all if params[0] and params[0].indexOf('deg') != -1
            return all if args.indexOf('-corner') != -1
            return all if args.indexOf('-side')   != -1

            params = @oldDirection(params)
            params = @colorStops(params)

            '-webkit-gradient(linear, ' + params.join(', ') + ')'
          else
            if params.length > 0
              if params[0][0..2] == 'to '
                params[0] = @fixDirection(params[0])
              else if params[0].indexOf('deg') != -1
                params[0] = @fixAngle(params[0])
              else if params[0].indexOf(' at ') != -1
                @fixRadial(params)
            before + prefix + @name + '(' + params.join(', ') + ')'

      prefixedDecls.join(',')

  # Direction to replace
  directions:
    top:    'bottom'
    left:   'right'
    bottom: 'top'
    right:  'left'

  # Direction to replace
  oldDirections:
    'top':    'left bottom, left top'
    'left':   'right top, left top'
    'bottom': 'left top, left bottom'
    'right':  'left top, right top'

    'top right':    'left bottom, right top'
    'top left':     'right bottom, left top'
    'bottom right': 'left top, right bottom'
    'bottom left':  'right top, left bottom'

  # Split gradients in background value
  splitDecls: (decl) ->
    decls       = []
    chunks      = decl.split(',')
    currentDecl = []
    for i in chunks
      # chunks starts with gradient declaration
{'fraction_non_alphanumeric': 0.13981152479530357, 'fraction_numerical': 0.006797466398887687, 'mean_word_length': 2.5338427947598254, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '916360', 'n_tokens_mistral': 1980, 'n_tokens_neox': 1910, 'n_words': 645}