<commit_before>var postcss = require( 'postcss' );
var mobileViewportunits = postcss.plugin( 'postcss-mobile-viewportunits', function( opts ) {
    opts = opts !== undefined ? opts : {
        devices: [
            // iPad
            {
                mediaquery: 'only screen and (-webkit-min-device-pixel-ratio: 1) and (device-width: 768px) and (device-height: 1024px) and (orientation: portrait)',
                width: 768,
                height: 1024
            },
            {
                mediaquery: 'only screen and (-webkit-min-device-pixel-ratio: 1) and (device-width: 768px) and (device-height: 1024px) and (orientation: landscape)',
                width: 1024,
                height: 768
            },

            // iPhone 4
            {
                mediaquery: 'only screen and (-webkit-min-device-pixel-ratio: 1) and (device-width: 320px) and (device-height: 480px) and (orientation: portrait)',
                width: 320,
                height: 480
            },
            {
                mediaquery: 'only screen and (-webkit-min-device-pixel-ratio: 1) and (device-width: 320px) and (device-height: 480px) and (orientation: landscape)',
                width: 480,
                height: 320
            },

            // iPhone 5, 5C, 5S
            {
                mediaquery: 'only screen and (-webkit-min-device-pixel-ratio: 1) and (device-width: 320px) and (device-height: 568px) and (orientation: portrait)',
                width: 320,
                height: 568
            },
            {
                mediaquery: 'only screen and (-webkit-min-device-pixel-ratio: 1) and (device-width: 320px) and (device-height: 568px) and (orientation: landscape)',
                width: 568,
                height: 320
            }
        ]
    };

    return function( css, result ) {
        var rules = {};
        css.walkDecls( function( decl ) {
            if ( decl.value.match(/(vh|vw)/) ) {

                var selector = decl.parent.selector;

                opts.devices.forEach( function( device ) {
                    var value = decl.value.replace(/(\d+)(vh|vw)/gi, function( fullUnit, value, unit) {
                        var relativeValue = Number(value) / 100;
                        var multiplier = (unit === 'vw') ? device.width : device.height;

                        return (relativeValue * multiplier) + 'px';
                    } );

                    if ( !rules[ device.mediaquery ] ) {
                        rules[ device.mediaquery ] = {};
                    }

                    if ( Array.isArray( rules[ device.mediaquery ][ selector ] ) === false ) {
                        rules[ device.mediaquery ][ selector ] = [];
                    }

                    var newDecl = postcss.decl( {
                        prop: decl.prop,
                        value: value
                    } );

                    rules[ device.mediaquery ][ selector ].push( newDecl );
                } );
            }
        } );

        for (var atrule in rules) {
            var selectors = rules[ atrule ];
            var newAtRule = postcss.atRule( {
                name: 'media',
                params: atrule
            } );

            for ( var selector in selectors ) {

                var newRule = postcss.rule( {
                    selector: selector
                } );

                selectors[ selector ].forEach( function( decl ) {
                    newRule.append( decl );
                } );

                newAtRule.append( newRule );
            }

            result.root.append( newAtRule );
        }

    };
} );

module.exports = mobileViewportunits;<commit_msg>Filter decls so no duplicate properties appear<commit_after>var postcss = require( 'postcss' );
var mobileViewportunits = postcss.plugin( 'postcss-mobile-viewportunits', function( opts ) {
    opts = opts !== undefined ? opts : {
        devices: [
            // iPad
            {
                mediaquery: 'only screen and (-webkit-min-device-pixel-ratio: 1) and (device-width: 768px) and (device-height: 1024px) and (orientation: portrait)',
                width: 768,
                height: 1024
            },
            {
                mediaquery: 'only screen and (-webkit-min-device-pixel-ratio: 1) and (device-width: 768px) and (device-height: 1024px) and (orientation: landscape)',
                width: 1024,
                height: 768
            },

            // iPhone 4
            {
                mediaquery: 'only screen and (-webkit-min-device-pixel-ratio: 1) and (device-width: 320px) and (device-height: 480px) and (orientation: portrait)',
                width: 320,
                height: 480
            },
            {
                mediaquery: 'only screen and (-webkit-min-device-pixel-ratio: 1) and (device-width: 320px) and (device-height: 480px) and (orientation: landscape)',
                width: 480,
                height: 320
            },

            // iPhone 5, 5C, 5S
            {
                mediaquery: 'only screen and (-webkit-min-device-pixel-ratio: 1) and (device-width: 320px) and (device-height: 568px) and (orientation: portrait)',
                width: 320,
                height: 568
            },
            {
                mediaquery: 'only screen and (-webkit-min-device-pixel-ratio: 1) and (device-width: 320px) and (device-height: 568px) and (orientation: landscape)',
                width: 568,
                height: 320
            }
        ]
    };

    return function( css, result ) {
        var rules = {};
        css.walkDecls( function( decl ) {
            if ( decl.value.match(/(vh|vw)/) ) {

                var selector = decl.parent.selector;

                opts.devices.forEach( function( device ) {
                    var value = decl.value.replace(/(\d+)(vh|vw)/gi, function( fullUnit, value, unit) {
                        var relativeValue = Number(value) / 100;
                        var multiplier = (unit === 'vw') ? device.width : device.height;

                        return (relativeValue * multiplier) + 'px';
                    } );

                    if ( !rules[ device.mediaquery ] ) {
                        rules[ device.mediaquery ] = {};
                    }

                    if ( Array.isArray( rules[ device.mediaquery ][ selector ] ) === false ) {
                        rules[ device.mediaquery ][ selector ] = [];
                    }

                    var newDecl = postcss.decl( {
                        prop: decl.prop,
                        value: value
                    } );

                    rules[ device.mediaquery ][ selector ].push( newDecl );
                } );
            }
        } );

        for (var atrule in rules) {
            var selectors = rules[ atrule ];
            var newAtRule = postcss.atRule( {
                name: 'media',
                params: atrule
            } );

            for ( var selector in selectors ) {
                var declsInTree = [];

                var newRule = postcss.rule( {
                    selector: selector
                } );

                selectors[ selector ].forEach( function( decl ) {
                    var matchingDecls = declsInTree.filter(function ( tDecl ) {
                        return decl.prop  === tDecl.prop && decl.value === tDecl.value;
                    });

                    if (matchingDecls.length === 0) {
                        declsInTree.push(decl);
                        newRule.append( decl );
                    }
                } );

                newAtRule.append( newRule );
            }

            result.root.append( newAtRule );
        }

    };
} );

module.exports = mobileViewportunits;
{'fraction_non_alphanumeric': 0.11385248008224107, 'fraction_numerical': 0.023001799023387302, 'mean_word_length': 1.2481224725592144, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4052992', 'n_tokens_mistral': 2247, 'n_tokens_neox': 1901, 'n_words': 498}