postcss-time-machine v4.0.0
PostCSS Time Machine
PostCSS Time Machine fixes mistakes in the design of CSS itself, as described by the CSSWG.
They specifically requested that these should be corrected “if anyone invents a time machine”.
npx postcss-time-machine SOURCE.css TRANSFORMED.cssSafe Fixes
These fixes do not change the way CSS normally works. They can be individually
disabled by passing their short name into the fixes option.
border-box
Box-sizing should be
border-boxby default.
/* prepended to your css */
* {
box-sizing: border-box;
}corner-radius
border-radiusshould becorner-radius.
button {
corner-radius: 3px;
}
/* becomes */
button {
border-radius: 3px;
}current-color
currentcolorshould becurrent-color.
button {
box-shadow: 0 0 5px solid current-color;
}
/* becomes */
button {
box-shadow: 0 0 5px solid currentColor;
}display-type
The
displayproperty should be calleddisplay-type.
.some-component {
display-type: grid;
}
/* becomes */
.some-component {
display: grid;
}marker-style
The
list-styleproperties should be calledmarker-style.
.georgian-list {
marker-style: square;
}
/* becomes */
.georgian-list {
list-style: square;
}no-wrap
In
white-space,nowrapshould be calledno-wrap.
h1 {
white-space: no-wrap;
}
/* becomes */
h1 {
white-space: nowrap;
}overflow-wrap
word-wrap/overflow-wrapshould not exist, andoverflow-wrapshould be a keyword onwhite-space.
a {
white-space: overflow-wrap;
}
/* becomes */
a {
word-wrap: break-word;
}rgb-hsl
rgb()andhsl()should have an optional fourth alpha parameter (which should use the same format as R, G, and B or S and L).
header {
background-color: rgb(0, 0, 255, 102);
color: hsl(170, 50%, 45%, 80%);
}
/* becomes */
header {
background-color: rgba(0, 0, 255, .4);
color: hsla(170, 50%, 45%, .8);
}text-middle
In
vertical-align,middleshould be calledtext-middle.
button {
vertical-align: text-middle;
}
/* becomes */
button {
vertical-align: middle;
}z-order
z-indexshould be calledz-orderordepth.
aside {
depth: 10;
}
figure {
z-order: 10;
}
/* becomes */
aside {
z-index: 10;
}
figure {
z-index: 10;
}Unsafe Fixes
These fixes change the way CSS normally works. They can be individually
enabled or disabled by passing their short name into the
fixes option, or by setting the
useUnsafeFixes option to false.
background-position
background-positionandborder-spacing(all 2-axis properties) should take vertical first, to match with the 4-direction properties likemargin.
body {
background-position: 0% 50%;
}
table {
border-spacing: 10px 5px;
}
/* becomes */
body {
background-position: 50% 0%;
}
table {
border-spacing: 5px 10px;
}background-size
In
background-size, having one value should duplicate its value, not default the second one toauto.
header {
background-size: 75%;
}
/* becomes */
header {
background-size: 75% 75%;
}line-height
line-height: <percentage>should compute to the equivalentline-height: <number>, so that it effectively inherits as a percentage not a length.
p {
line-height: 200%;
}
/* becomes */
p {
line-height: 2;
}link-pseudo
:linkshould have had the:any-linksemantics all along.
:link {
color: blue;
}
/* becomes */
:link, :visited {
color: blue;
}Advanced Usage
Add PostCSS Time Machine to your project:
npm install postcss-time-machine --save-devUse PostCSS Time Machine to process your CSS:
const postcssTimeMachine = require('postcss-time-machine');
postcssTimeMachine.process(YOUR_CSS /*, processOptions, pluginOptions */);Or use it as a PostCSS plugin:
const postcss = require('postcss');
const postcssTimeMachine = require('postcss-time-machine');
postcss([
postcssTimeMachine(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);PostCSS Time Machine runs in all Node environments, with special instructions for:
| Node | PostCSS CLI | Webpack | Create React App | Gulp | Grunt |
|---|
Options
fixes
The fixes option lets you individually enable or disable individual fixes.
postcssTimeMachine({
fixes: {
'border-box': false // disables adding * { box-sizing: border-box; }
}
})useUnsafeFixes
The useUnsafeFixes option determines whether unsafe fixes will be applied or
not. Individual features passed into the fixes option will override this. By
default, unsafe features are enabled.
postcssTimeMachine({
useUnsafeFixes: false // disables background-position, background-size, and line-height
})