/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2014 Leinardo Smith
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 */


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, brackets, $, less */

define(function (require, exports, module) {
    "use strict";
    
    /**
     * Map of registered shorthand providers by css shorthand property name.
     * See {@link #registerShorthandProvider()}.
     * @type {Object.<{Object>}
     */
    var shorthandProvidersMap = {};

    function registerShorthandProvider(shorthandPropertyName, provider) {
        shorthandProvidersMap[shorthandPropertyName] = provider;
    }

    function getProviderForProperty(shorthandPropertyName) {
        return shorthandProvidersMap[shorthandPropertyName];
    }

    /**
     * @param {Array<{string}>} vals Array with 1 - 4 values
     * @return {Array<{string}>} vals Array with 4 values
     */
    function expandTRBLValues(vals) {
        return [
            vals[0],
            vals[1] || vals[0],
            vals[2] || vals[0],
            vals[3] || vals[1] || vals[0]
        ];
    }

    /**
     * @param {Array<{string}>} vals Array with 4 values
     * @return {Array<{string}>} vals Array with 1 - 4 values
     */
    function collapseTRBLValues(vals) {
        var ret = [vals[0]];
        if (vals[0] === vals[2] && vals[1] === vals[3]) {
            if (vals[0] !== vals[1]) {
                ret.push(vals[1]);
            }
        } else {
            ret.push(vals[1]);
            ret.push(vals[2]);
            ret.push(vals[3]);
        }
        return ret;
    }

    /**
     * @param {string} propName
     * @param {Array<{prop:{string}, values.values:{Array<{string}}}>} declList
     */
    function findPropInDecList(propName, declList) {
        var i;
        for (i = 0; i < declList.length; i++) {
            if (declList[i].prop === propName) {
                return declList[i];
            }
        }
        return null;
    }

    /**
     * Convert CSS Declaration from text to  Object format
     * @param {string} declText
     * @return {prop: {string}, val: {string}}
     */
    function parseDeclarationList(declText) {
        var declList = [],
            regex = /([a-zA-Z\-]+):\s*([^;]*);/,
            match = declText.match(regex);

        while (match && match.length === 3) {
            declList.push({ prop: match[1], val: match[2] });

            declText = declText.substring(match.index + match[0].length);
            match = declText.match(regex);
        }
        
        return declList;
    }

    /**
     * Convert CSS DeclarationList from Object format to text
     * @param {Array<{prop:{string}, val:{string}}>} declList
     * @return {string}
     */
    function unparseDeclarationList(declList) {
        var i, text = "";
        declList.forEach(function (decl) {
            text += decl.prop + ": " + decl.val + ";\n";
        });

        return text;
    }
    
    /**
     * Helper function to convert whitespace separated values to an array
     * @param {string} str
     * @return Array<{string}>
     */
    function wsvToArray(str) {
        // Split on whitespace
        var arr = str.split(/\s/);

        // leading, trailing, and multiple whitespace creates empty elements,
        // so remove them.
        var filtered = arr.filter(function (element) {
            return (element !== "");
        });

        return filtered;
    }

    /**
     * Convert from one list of properties to another. This can be used to convert:
     *  - from a single shorthand prop to multiple longhand props
     *  - from multiple longhand props to a single shorthand prop
     *
     * @param {Array<{prop: {string}, val: {string}}>} declList
     * @param {Array<{string}>} toProps
     * @return Array<{string}> values that map to toProps array
     */
    function convertProps(declList, toProps) {
        var values = [],
            $test = $('<div/>');

        // Apply the "from" decls to the jQuery temp element
        declList.forEach(function (decl) {
            $test.css(decl.prop, decl.val);
        });

        // Use the jQuery temp element to get value for each toProp
        toProps.forEach(function (toProp) {
            values.push($test.css(toProp));
        });

        return values;
    }

    // public API
    exports.registerShorthandProvider   = registerShorthandProvider;
    exports.getProviderForProperty      = getProviderForProperty;

    // Utility functions
    exports.expandTRBLValues            = expandTRBLValues;
    exports.collapseTRBLValues          = collapseTRBLValues;
    exports.convertProps                = convertProps;
    exports.findPropInDecList           = findPropInDecList;
    exports.parseDeclarationList        = parseDeclarationList;
    exports.unparseDeclarationList      = unparseDeclarationList;
    exports.wsvToArray                  = wsvToArray;
});

@@ -4509,881 +4509,8 @@
  %7D%0A%0A
-    /**%0A     * Convert from one list of properties to another. This can be used to convert:%0A     *  - from a single shorthand prop to multiple longhand props%0A     *  - from multiple longhand props to a single shorthand prop%0A     *%0A     * @param %7BArray%3C%7Bprop: %7Bstring%7D, val: %7Bstring%7D%7D%3E%7D declList%0A     * @param %7BArray%3C%7Bstring%7D%3E%7D toProps%0A     * @return Array%3C%7Bstring%7D%3E values that map to toProps array%0A     */%0A    function convertProps(declList, toProps) %7B%0A        var values = %5B%5D,%0A            $test = $('%3Cdiv/%3E');%0A%0A        // Apply the %22from%22 decls to the jQuery temp element%0A        declList.forEach(function (decl) %7B%0A            $test.css(decl.prop, decl.val);%0A        %7D);%0A%0A        // Use the jQuery temp element to get value for each toProp%0A        toProps.forEach(function (toProp) %7B%0A            values.push($test.css(toProp));%0A        %7D);%0A%0A        return values;%0A    %7D%0A%0A
     
@@ -4810,64 +4810,8 @@
 es;%0A
-    exports.convertProps                = convertProps;%0A
     

Remove convertProps function