A PostCSS plugin that ensures CSS property values are consistently ordered for optimization.
npx @tessl/cli install tessl/npm-postcss-ordered-values@7.0.0postcss-ordered-values is a PostCSS plugin that ensures CSS property values are consistently ordered. It normalizes properties that accept values in arbitrary order (such as border, animation, transition, etc.) to make it easier for other CSS optimization tools to identify duplicate declarations and improve compression.
npm install postcss-ordered-valuesconst orderedValues = require('postcss-ordered-values');For TypeScript:
import orderedValues = require('postcss-ordered-values');
// or
const orderedValues = require('postcss-ordered-values');const postcss = require('postcss');
const orderedValues = require('postcss-ordered-values');
// Process CSS with the plugin
const result = postcss([orderedValues()])
.process(css, { from: undefined });
console.log(result.css);Input CSS:
h1 {
border: solid 1px red;
border: red solid .5em;
border: rgba(0, 30, 105, 0.8) solid 1px;
border: 1px solid red;
}Output CSS:
h1 {
border: 1px solid red;
border: .5em solid red;
border: 1px solid rgba(0, 30, 105, 0.8);
border: 1px solid red;
}Additional Examples:
// Animation property normalization
const css1 = 'div { animation: bounce infinite 2s ease-in-out; }';
// Result: div { animation: bounce 2s ease-in-out infinite; }
// Box shadow with inset
const css2 = 'div { box-shadow: red 10px 10px inset; }';
// Result: div { box-shadow: inset 10px 10px red; }
// Flex flow ordering
const css3 = 'div { flex-flow: wrap column; }';
// Result: div { flex-flow: column wrap; }
// Grid auto flow
const css4 = 'div { grid-auto-flow: dense row; }';
// Result: div { grid-auto-flow: row dense; }The plugin operates through several key components:
Creates a PostCSS plugin that processes CSS declarations to normalize property value order.
/**
* Creates a PostCSS plugin for ordering CSS property values
* @returns {Plugin} PostCSS plugin instance
*/
function pluginCreator(): Plugin;The plugin processes CSS declarations during the OnceExit phase, after all other transformations are complete. It maintains a cache of processed values to improve performance on repeated values.
The plugin handles the following CSS properties and their vendor-prefixed variants:
border, border-top, border-right, border-bottom, border-leftborder-block, border-inline, border-block-start, border-block-endborder-inline-start, border-inline-endoutlinecolumn-ruleNormalization Order: <width> <style> <color>
animation, -webkit-animationNormalization Order: <name> <duration> <timing-function> <delay> <iteration-count> <direction> <fill-mode> <play-state>
box-shadowNormalization Order: <inset> <length-values> <color>
flex-flowNormalization Order: <flex-direction> <flex-wrap>
grid-auto-flowgrid-column-gap, grid-row-gapgrid-column, grid-rowgrid-column-start, grid-column-endgrid-row-start, grid-row-endGrid Auto Flow Normalization Order: <row/column> <dense>
Grid Gap Normalization: Normalizes normal keyword to front position when present
list-styleNormalization Order: <type> <position> <image>
transition, -webkit-transitionNormalization Order: <property> <duration> <timing-function> <delay>
columnsNormalization Order: <width> <count> (only transforms valid two-value declarations)
The plugin includes intelligent processing controls:
var(), env(), constant()) are detectedcalc(), clamp(), max(), min()) - may abort processing in complex contexts to avoid incorrect transformationsThe plugin gracefully handles various edge cases:
___CSS_LOADER_IMPORT___) abort processing// Plugin identifier for PostCSS
pluginCreator.postcss = true;For TypeScript users, the plugin exports match the actual type definitions:
/**
* Main plugin creator function exported via CommonJS
*/
declare function pluginCreator(): import("postcss").Plugin;
declare namespace pluginCreator {
let postcss: true;
}
export = pluginCreator;