Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-merge-longhand

Package Overview
Dependencies
Maintainers
4
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-merge-longhand - npm Package Compare versions

Comparing version 4.0.10 to 4.0.11

12

dist/lib/canExplode.js

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -7,3 +7,3 @@ Object.defineProperty(exports, "__esModule", {

var _isCustomProp = require('./isCustomProp');
var _isCustomProp = require("./isCustomProp");

@@ -14,5 +14,5 @@ var _isCustomProp2 = _interopRequireDefault(_isCustomProp);

const hasInherit = node => node.value.includes('inherit');
const hasInitial = node => node.value.includes('initial');
const hasUnset = node => node.value.includes('unset');
const hasInherit = node => node.value.toLowerCase().includes("inherit");
const hasInitial = node => node.value.toLowerCase().includes("initial");
const hasUnset = node => node.value.toLowerCase().includes("unset");

@@ -27,2 +27,2 @@ exports.default = (prop, includeCustomProps = true) => {

module.exports = exports['default'];
module.exports = exports["default"];

@@ -16,5 +16,5 @@ 'use strict';

const hasInherit = node => node.value.includes('inherit');
const hasInitial = node => node.value.includes('initial');
const hasUnset = node => node.value.includes('unset');
const hasInherit = node => node.value.toLowerCase() === 'inherit';
const hasInitial = node => node.value.toLowerCase() === 'initial';
const hasUnset = node => node.value.toLowerCase() === 'unset';

@@ -21,0 +21,0 @@ exports.default = (props, includeCustomProps = true) => {

@@ -100,3 +100,3 @@ 'use strict';

for (let i = 0; i < precedence.length; i++) {
if (!!~precedence[i].indexOf(prop)) {
if (!!~precedence[i].indexOf(prop.toLowerCase())) {
return i;

@@ -122,9 +122,9 @@ }

function diffingProps(values, nextValues) {
const diff = wsc.reduce((prev, curr, i) => {
return wsc.reduce((prev, curr, i) => {
if (values[i] === nextValues[i]) {
return prev;
}
return [...prev, curr];
}, []);
return diff;
}

@@ -140,6 +140,9 @@

}
const diff = diffingProps(values, nextValues);
if (diff.length > 1) {
return;
}
const prop = diff.pop();

@@ -152,2 +155,3 @@ const position = wsc.indexOf(prop);

let props = (0, _parseTrbl2.default)(values[position]);
props[index] = nextValues[position];

@@ -166,2 +170,3 @@

}
if (newLength2 < newLength1 && newLength2 < origLength) {

@@ -181,5 +186,7 @@ decl.value = borderValue2;

a = Array.isArray(a) ? a : [a];
if (!~a.indexOf(b)) {
a.push(b);
}
return a;

@@ -190,3 +197,3 @@ });

function explode(rule) {
rule.walkDecls(/^border/, decl => {
rule.walkDecls(/^border/i, decl => {
if (!(0, _canExplode2.default)(decl, false)) {

@@ -200,3 +207,4 @@ return;

const { prop } = decl;
const prop = decl.prop.toLowerCase();
// border -> border-trbl

@@ -208,8 +216,11 @@ if (prop === 'border') {

});
return decl.remove();
}
}
// border-trbl -> border-trbl-wsc
if (directions.some(direction => prop === direction)) {
let values = (0, _parseWsc2.default)(decl.value);
if ((0, _validateWsc.isValidWsc)(values)) {

@@ -222,5 +233,7 @@ wsc.forEach((d, i) => {

});
return decl.remove();
}
}
// border-wsc -> border-trbl-wsc

@@ -231,2 +244,3 @@ wsc.some(style => {

}
(0, _parseTrbl2.default)(decl.value).forEach((value, i) => {

@@ -238,2 +252,3 @@ (0, _insertCloned2.default)(decl.parent, decl, {

});
return decl.remove();

@@ -248,2 +263,3 @@ });

const prop = borderProperty(direction);
(0, _mergeRules2.default)(rule, wsc.map(style => borderProperty(direction, style)), (rules, lastNode) => {

@@ -255,3 +271,5 @@ if ((0, _canMerge2.default)(rules, false) && !rules.some(_stylehacks.detect)) {

});
rules.forEach(_remove2.default);
return true;

@@ -265,2 +283,3 @@ }

const prop = borderProperty(style);
(0, _mergeRules2.default)(rule, _trbl2.default.map(direction => borderProperty(direction, style)), (rules, lastNode) => {

@@ -272,3 +291,5 @@ if ((0, _canMerge2.default)(rules) && !rules.some(_stylehacks.detect)) {

});
rules.forEach(_remove2.default);
return true;

@@ -284,12 +305,18 @@ }

}
const values = rules.map(({ value }) => value);
if (!canMergeValues(values)) {
return;
}
const parsed = values.map(value => (0, _parseWsc2.default)(value));
if (!parsed.every(_validateWsc.isValidWsc)) {
return;
}
wsc.forEach((d, i) => {
const value = parsed.map(v => v[i] || defaults[i]);
if (canMergeValues(value)) {

@@ -304,3 +331,5 @@ (0, _insertCloned2.default)(lastNode.parent, lastNode, {

});
rules.forEach(_remove2.default);
return true;

@@ -316,7 +345,10 @@ });

}
const values = rules.map(node => (0, _parseTrbl2.default)(node.value));
const mapped = [0, 1, 2, 3].map(i => [values[0][i], values[1][i], values[2][i]].join(' '));
if (!canMergeValues(mapped)) {
return;
}
const [width, style, color] = rules;

@@ -343,2 +375,3 @@ const reduced = getDistinctShorthands(mapped);

rules.forEach(_remove2.default);
return true;

@@ -350,3 +383,4 @@ } else if (reduced.length === 1) {

}));
rules.filter(node => node.prop !== properties[2]).forEach(_remove2.default);
rules.filter(node => node.prop.toLowerCase() !== properties[2]).forEach(_remove2.default);
return true;

@@ -361,2 +395,3 @@ }

}
const values = rules.map(node => (0, _parseTrbl2.default)(node.value));

@@ -387,2 +422,3 @@ const mapped = [0, 1, 2, 3].map(i => [values[0][i], values[1][i], values[2][i]].join(' '));

rules.forEach(_remove2.default);
return true;

@@ -401,5 +437,7 @@ }

const wscValue = (0, _parseWsc2.default)(node.value);
if (!(0, _validateWsc.isValidWsc)(wscValue)) {
return node.value;
}
return wscValue.map((value, i) => value || defaults[i]).join(' ');

@@ -426,3 +464,5 @@ });

}
rules.forEach(_remove2.default);
return true;

@@ -436,2 +476,3 @@ }

const prop = `${direction}-${style}`;
(0, _mergeRules2.default)(rule, [direction, prop], (rules, lastNode) => {

@@ -443,2 +484,3 @@ if (lastNode.prop !== direction) {

const values = (0, _parseWsc2.default)(lastNode.value);
if (!(0, _validateWsc.isValidWsc)(values)) {

@@ -449,2 +491,3 @@ return;

const wscProp = rules.filter(r => r !== lastNode)[0];
if (!isValueCustomProp(values[i]) || (0, _isCustomProp2.default)(wscProp)) {

@@ -455,2 +498,3 @@ return;

const wscValue = values[i];
values[i] = wscProp.value;

@@ -464,3 +508,5 @@

lastNode.value = (0, _minifyWsc2.default)(values);
wscProp.remove();
return true;

@@ -481,2 +527,3 @@ }

const values = (0, _parseWsc2.default)(lastNode.value);
if (!(0, _validateWsc.isValidWsc)(values)) {

@@ -487,2 +534,3 @@ return;

const wscProp = rules.filter(r => r !== lastNode)[0];
if (!isValueCustomProp(values[i]) || (0, _isCustomProp2.default)(wscProp)) {

@@ -493,2 +541,3 @@ return;

const wscValue = values[i];
values[i] = wscProp.value;

@@ -503,2 +552,3 @@

wscProp.remove();
return true;

@@ -511,13 +561,20 @@ }

let decls = (0, _getDecls2.default)(rule, directions);
while (decls.length) {
const lastNode = decls[decls.length - 1];
wsc.forEach((d, i) => {
const names = directions.filter(name => name !== lastNode.prop).map(name => `${name}-${d}`);
let nodes = rule.nodes.slice(0, rule.nodes.indexOf(lastNode));
const border = (0, _getLastNode2.default)(nodes, 'border');
if (border) {
nodes = nodes.slice(nodes.indexOf(border));
}
const props = nodes.filter(node => node.prop && ~names.indexOf(node.prop) && node.important === lastNode.important);
const rules = (0, _getRules2.default)(props, names);
if ((0, _hasAllProps2.default)(rules, ...names) && !rules.some(_stylehacks.detect)) {

@@ -527,8 +584,13 @@ const values = rules.map(node => node ? node.value : null);

const lastNodeValue = _postcss.list.space(lastNode.value)[i];
values[directions.indexOf(lastNode.prop)] = lastNodeValue;
let value = (0, _minifyTrbl2.default)(values.join(' '));
if (filteredValues[0] === filteredValues[1] && filteredValues[1] === filteredValues[2]) {
value = filteredValues[0];
}
let refNode = props[props.length - 1];
if (value === lastNodeValue) {

@@ -540,2 +602,3 @@ refNode = lastNode;

}
(0, _insertCloned2.default)(refNode.parent, refNode, {

@@ -545,2 +608,3 @@ prop: borderProperty(d),

});
decls = decls.filter(node => !~rules.indexOf(node));

@@ -550,2 +614,3 @@ rules.forEach(_remove2.default);

});
decls = decls.filter(node => node !== lastNode);

@@ -556,9 +621,13 @@ }

const nextDecl = decl.next();
if (!nextDecl || nextDecl.type !== 'decl') {
return;
}
const index = directions.indexOf(nextDecl.prop);
if (!~index) {
return;
}
const values = (0, _parseWsc2.default)(decl.value);

@@ -582,12 +651,16 @@ const nextValues = (0, _parseWsc2.default)(nextDecl.value);

rule.walkDecls(/^border($|-(top|right|bottom|left)$)/, decl => {
rule.walkDecls(/^border($|-(top|right|bottom|left)$)/i, decl => {
let values = (0, _parseWsc2.default)(decl.value);
if (!(0, _validateWsc.isValidWsc)(values)) {
return;
}
const position = directions.indexOf(decl.prop);
let dirs = [...directions];
dirs.splice(position, 1);
wsc.forEach((d, i) => {
const props = dirs.map(dir => `${dir}-${d}`);
(0, _mergeRules2.default)(rule, [decl.prop, ...props], rules => {

@@ -599,4 +672,6 @@ if (!rules.includes(decl)) {

const longhands = rules.filter(p => p !== decl);
if (longhands[0].value === longhands[1].value && longhands[1].value === longhands[2].value && longhands[0].value === values[i]) {
if (longhands[0].value.toLowerCase() === longhands[1].value.toLowerCase() && longhands[1].value.toLowerCase() === longhands[2].value.toLowerCase() && longhands[0].value.toLowerCase() === values[i].toLowerCase()) {
longhands.forEach(_remove2.default);
(0, _insertCloned2.default)(decl.parent, decl, {

@@ -606,6 +681,9 @@ prop: borderProperty(d),

});
values[i] = null;
}
});
const newValue = values.join(' ');
if (newValue) {

@@ -620,3 +698,3 @@ decl.value = newValue;

// clean-up values
rule.walkDecls(/^border($|-(top|right|bottom|left)$)/, decl => {
rule.walkDecls(/^border($|-(top|right|bottom|left)$)/i, decl => {
decl.value = (0, _minifyWsc2.default)(decl.value);

@@ -626,3 +704,3 @@ });

// border-spacing-hv -> border-spacing
rule.walkDecls('border-spacing', decl => {
rule.walkDecls(/^border-spacing$/i, decl => {
const value = _postcss.list.space(decl.value);

@@ -638,2 +716,3 @@

decls = (0, _getDecls2.default)(rule, allProperties);
while (decls.length) {

@@ -644,3 +723,3 @@ const lastNode = decls[decls.length - 1];

// remove properties of lower precedence
const lesser = decls.filter(node => !(0, _stylehacks.detect)(lastNode) && !(0, _stylehacks.detect)(node) && !(0, _isCustomProp2.default)(lastNode) && node !== lastNode && node.important === lastNode.important && getLevel(node.prop) > getLevel(lastNode.prop) && (!!~node.prop.indexOf(lastNode.prop) || node.prop.endsWith(lastPart)));
const lesser = decls.filter(node => !(0, _stylehacks.detect)(lastNode) && !(0, _stylehacks.detect)(node) && !(0, _isCustomProp2.default)(lastNode) && node !== lastNode && node.important === lastNode.important && getLevel(node.prop) > getLevel(lastNode.prop) && (!!~node.prop.toLowerCase().indexOf(lastNode.prop) || node.prop.toLowerCase().endsWith(lastPart)));

@@ -654,8 +733,11 @@ lesser.forEach(_remove2.default);

if (duplicates.length) {
if (/hsla|rgba/.test(getColorValue(lastNode))) {
const preserve = duplicates.filter(node => !/hsla|rgba/.test(getColorValue(node))).pop();
if (/hsla\(|rgba\(/i.test(getColorValue(lastNode))) {
const preserve = duplicates.filter(node => !/hsla\(|rgba\(/i.test(getColorValue(node))).pop();
duplicates = duplicates.filter(node => node !== preserve);
}
duplicates.forEach(_remove2.default);
}
decls = decls.filter(node => node !== lastNode && !~duplicates.indexOf(node));

@@ -662,0 +744,0 @@ }

@@ -60,2 +60,3 @@ 'use strict';

let decls = (0, _getDecls2.default)(rule, [prop].concat(properties));
while (decls.length) {

@@ -72,2 +73,3 @@ const lastNode = decls[decls.length - 1];

let duplicates = decls.filter(node => !(0, _stylehacks.detect)(lastNode) && !(0, _stylehacks.detect)(node) && node !== lastNode && node.important === lastNode.important && node.prop === lastNode.prop && !(!(0, _isCustomProp2.default)(node) && (0, _isCustomProp2.default)(lastNode)));
duplicates.forEach(_remove2.default);

@@ -80,10 +82,13 @@ decls = decls.filter(node => node !== lastNode && !~duplicates.indexOf(node));

explode: rule => {
rule.walkDecls(prop, decl => {
rule.walkDecls(new RegExp("^" + prop + "$", "i"), decl => {
if (!(0, _canExplode2.default)(decl)) {
return;
}
if ((0, _stylehacks.detect)(decl)) {
return;
}
const values = (0, _parseTrbl2.default)(decl.value);
_trbl2.default.forEach((direction, index) => {

@@ -95,2 +100,3 @@ (0, _insertCloned2.default)(decl.parent, decl, {

});
decl.remove();

@@ -107,5 +113,7 @@ });

rules.forEach(_remove2.default);
return true;
}
});
cleanup(rule);

@@ -112,0 +120,0 @@ }

@@ -61,11 +61,14 @@ 'use strict';

function normalize(values) {
if (values[0] === auto) {
if (values[0].toLowerCase() === auto) {
return values[1];
}
if (values[1] === auto) {
if (values[1].toLowerCase() === auto) {
return values[0];
}
if (values[0] === inherit && values[1] === inherit) {
if (values[0].toLowerCase() === inherit && values[1].toLowerCase() === inherit) {
return inherit;
}
return values.join(' ');

@@ -75,10 +78,13 @@ }

function explode(rule) {
rule.walkDecls('columns', decl => {
rule.walkDecls(/^columns$/i, decl => {
if (!(0, _canExplode2.default)(decl)) {
return;
}
if ((0, _stylehacks.detect)(decl)) {
return;
}
let values = _postcss.list.space(decl.value);
if (values.length === 1) {

@@ -91,3 +97,3 @@ values.push(auto);

if (value === auto) {
if (value.toLowerCase() === auto) {
prop = properties[i];

@@ -103,2 +109,3 @@ } else if ((0, _postcssValueParser.unit)(value).unit) {

});
decl.remove();

@@ -110,2 +117,3 @@ });

let decls = (0, _getDecls2.default)(rule, ['columns'].concat(properties));
while (decls.length) {

@@ -135,6 +143,9 @@ const lastNode = decls[decls.length - 1];

});
rules.forEach(_remove2.default);
return true;
}
});
cleanup(rule);

@@ -141,0 +152,0 @@ }

@@ -8,4 +8,4 @@ "use strict";

function getDecls(rule, properties) {
return rule.nodes.filter(({ prop }) => prop && ~properties.indexOf(prop));
return rule.nodes.filter(({ prop }) => prop && ~properties.indexOf(prop.toLowerCase()));
}
module.exports = exports["default"];

@@ -8,5 +8,5 @@ "use strict";

exports.default = (rule, prop) => {
return rule.filter(n => n.prop && n.prop === prop).pop();
return rule.filter(n => n.prop && n.prop.toLowerCase() === prop).pop();
};
module.exports = exports["default"];

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -8,3 +8,3 @@ Object.defineProperty(exports, "__esModule", {

var _getLastNode = require('./getLastNode');
var _getLastNode = require("./getLastNode");

@@ -20,2 +20,2 @@ var _getLastNode2 = _interopRequireDefault(_getLastNode);

}
module.exports = exports['default'];
module.exports = exports["default"];

@@ -8,5 +8,5 @@ "use strict";

exports.default = (rule, ...props) => {
return props.every(p => rule.some(({ prop }) => prop && ~prop.indexOf(p)));
return props.every(p => rule.some(({ prop }) => prop && ~prop.toLowerCase().indexOf(p)));
};
module.exports = exports["default"];

@@ -9,5 +9,7 @@ "use strict";

const newNode = Object.assign(decl.clone(), props);
rule.insertAfter(decl, newNode);
return newNode;
};
module.exports = exports["default"];

@@ -26,8 +26,12 @@ 'use strict';

}
const parts = propA.prop.split('-');
return parts.some(() => {
parts.pop();
return parts.join('-') === propB.prop;
});
}
function hasConflicts(match, nodes) {

@@ -37,2 +41,3 @@ const firstNode = Math.min.apply(null, match.map(n => nodes.indexOf(n)));

const between = nodes.slice(firstNode + 1, lastNode);
return match.some(a => between.some(b => isConflictingProp(a, b)));

@@ -43,2 +48,3 @@ }

let decls = (0, _getDecls2.default)(rule, properties);
while (decls.length) {

@@ -48,2 +54,3 @@ const last = decls[decls.length - 1];

const rules = (0, _getRules2.default)(props, properties);
if ((0, _hasAllProps2.default)(rules, ...properties) && !hasConflicts(rules, rule.nodes)) {

@@ -54,2 +61,3 @@ if (callback(rules, last, props)) {

}
decls = decls.filter(node => node !== last);

@@ -56,0 +64,0 @@ }

@@ -15,6 +15,9 @@ 'use strict';

const value = (0, _parseTrbl2.default)(v);
if (value[3] === value[1]) {
value.pop();
if (value[2] === value[0]) {
value.pop();
if (value[0] === value[1]) {

@@ -25,2 +28,3 @@ value.pop();

}
return value.join(' ');

@@ -27,0 +31,0 @@ };

@@ -23,2 +23,3 @@ 'use strict';

const values = (0, _parseWsc2.default)(v);
if (!(0, _validateWsc.isValidWsc)(values)) {

@@ -32,4 +33,6 @@ return (0, _minifyTrbl2.default)(v);

}
return cur + ' ' + prev;
}).trim();
return (0, _minifyTrbl2.default)(value || 'none');

@@ -36,0 +39,0 @@ };

@@ -29,2 +29,3 @@ 'use strict';

const values = _postcss.list.space(value);
if (values.length > 1 && (0, _validateWsc.isStyle)(values[1]) && values[0].toLowerCase() === 'none') {

@@ -53,5 +54,7 @@ values.unshift();

}
if (width && !style && color) {
style = unknown.pop();
}
if (width && style && !color) {

@@ -58,0 +61,0 @@ color = unknown.pop();

@@ -1,2 +0,2 @@

'use strict';
"use strict";

@@ -11,3 +11,3 @@ Object.defineProperty(exports, "__esModule", {

var _cssColorNames = require('css-color-names');
var _cssColorNames = require("css-color-names");

@@ -18,4 +18,4 @@ var _cssColorNames2 = _interopRequireDefault(_cssColorNames);

const widths = ['thin', 'medium', 'thick'];
const styles = ['none', 'hidden', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset'];
const widths = ["thin", "medium", "thick"];
const styles = ["none", "hidden", "dotted", "dashed", "solid", "double", "groove", "ridge", "inset", "outset"];
const colors = Object.keys(_cssColorNames2.default);

@@ -35,2 +35,3 @@

}
value = value.toLowerCase();

@@ -49,7 +50,8 @@

}
if (value === 'transparent') {
if (value === "transparent") {
return true;
}
if (value === 'currentcolor') {
if (value === "currentcolor") {
return true;

@@ -56,0 +58,0 @@ }

{
"name": "postcss-merge-longhand",
"version": "4.0.10",
"version": "4.0.11",
"description": "Merge longhand properties into shorthand with PostCSS.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc