UNPKG

brandeur-plugin-enforce-longhands

Version:

Brandeur plugin that enforces longhand properties over shorthand properties

121 lines 5.27 kB
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } import sortProperty from 'brandeur-plugin-sort-properties'; function capitalize(str) { return str.charAt(0).toUpperCase() + str.slice(1); } function getPropertyPriority(_ref) { var borderLonghand = _ref.borderLonghand, borderDirectional = _ref.borderDirectional, borderDirectionalLonghand = _ref.borderDirectionalLonghand; var propertyPriority = { marginLeft: 2, marginRight: 2, marginTop: 2, marginBottom: 2, marginInline: 2, marginBlock: 2, marginInlineStart: 3, marginInlineEnd: 3, marginBlockStart: 3, marginBlockEnd: 3, paddingLeft: 2, paddingRight: 2, paddingBottom: 2, paddingTop: 2, paddingInline: 2, paddingBlock: 2, paddingInlineStart: 3, paddingInlineEnd: 3, paddingBlockStart: 3, paddingBlockEnd: 3, flexWrap: 2, flexShrink: 2, flexBasis: 2, backgroundColor: 2, backgroundRepeat: 2, backgroundPosition: 2, backgroundImage: 2, backgroundOrigin: 2, backgroundClip: 2, backgroundSize: 2, transitionProperty: 2, transitionTimingFunction: 2, transitionDuration: 2, transitionDelay: 2, animationDelay: 2, animationDirection: 2, animationDuration: 2, animationFillMode: 2, animationIterationCount: 2, animationName: 2, animationPlayState: 2, animationTimingFunction: 2, borderWidth: borderLonghand, borderStyle: borderLonghand, borderColor: borderLonghand, // these conflict with the longhands above borderTop: borderDirectional, borderRight: borderDirectional, borderBottom: borderDirectional, borderLeft: borderDirectional, borderTopWidth: borderDirectionalLonghand, borderTopStyle: borderDirectionalLonghand, borderTopColor: borderDirectionalLonghand, borderRightWidth: borderDirectionalLonghand, borderRightStyle: borderDirectionalLonghand, borderRightColor: borderDirectionalLonghand, borderBottomWidth: borderDirectionalLonghand, borderBottomStyle: borderDirectionalLonghand, borderBottomColor: borderDirectionalLonghand, borderLeftWidth: borderDirectionalLonghand, borderLeftStyle: borderDirectionalLonghand, borderLeftColor: borderDirectionalLonghand, borderBottomLeftRadius: 2, borderBottomRightRadius: 2, borderTopLeftRadius: 2, borderTopRightRadius: 2, borderImageOutset: 2, borderImageRepeat: 2, borderImageSlice: 2, borderImageSource: 2, borderImageWidth: 2, columnWidth: 2, columnCount: 2, listStyleImage: 2, listStylePosition: 2, listStyleType: 2, outlineWidth: 2, outlineStyle: 2, outlineColor: 2, overflowX: 2, overflowY: 2, textDecorationLine: 2, textDecorationStyle: 2, textDecorationColor: 2 }; // Add all possible vendor prefixes to all properties // brandeur-plugin-prefixer converts properties to prefixed ones like `WebkitBackgroundColor` return Object.entries(propertyPriority).reduce(function (acc, _ref2) { var _ref3 = _slicedToArray(_ref2, 2), property = _ref3[0], priority = _ref3[1]; acc['Webkit' + capitalize(property)] = priority; return acc; }, propertyPriority); } export default function enforceLonghandsPlugin() { var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, _ref4$borderMode = _ref4.borderMode, borderMode = _ref4$borderMode === void 0 ? 'none' : _ref4$borderMode; var propertyPriority = getPropertyPriority({ borderDirectional: borderMode === 'directional' ? 3 : 2, borderLonghand: borderMode === 'longhand' ? 3 : 2, borderDirectionalLonghand: borderMode === 'none' ? 3 : 4 }); return sortProperty(propertyPriority); }