All Projects → shiwaforce → Postcss High Contrast

shiwaforce / Postcss High Contrast

Licence: mit
Create high contrast version of your project with ease.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Postcss High Contrast

Postcss Plugins
The "officially unofficial" consolidated list of PostCSS plugins in a ready-to-use package
Stars: ✭ 107 (-0.93%)
Mutual labels:  postcss, postcss-plugins
react-cli
基于 create-react-app 搭建的前端脚手架
Stars: ✭ 18 (-83.33%)
Mutual labels:  postcss, postcss-plugins
postcss-if-media
A PostCSS plugin to inline or nest media queries within CSS rules & properties.
Stars: ✭ 35 (-67.59%)
Mutual labels:  postcss, postcss-plugins
Postcss Aspect Ratio Mini
A PostCSS plugin to fix an element's dimensions to an aspect ratio
Stars: ✭ 123 (+13.89%)
Mutual labels:  postcss, postcss-plugins
Stencil Postcss
Autoprefixer plugin for Stencil
Stars: ✭ 19 (-82.41%)
Mutual labels:  postcss, postcss-plugins
Stylefmt
stylefmt is a tool that automatically formats stylesheets.
Stars: ✭ 2,123 (+1865.74%)
Mutual labels:  postcss, postcss-plugins
postcss-gtk
Processes GTK+ CSS into browser CSS
Stars: ✭ 23 (-78.7%)
Mutual labels:  postcss, postcss-plugins
Rucksack
A little bag of CSS superpowers, built on PostCSS
Stars: ✭ 1,861 (+1623.15%)
Mutual labels:  postcss, postcss-plugins
Postcss Start To End
PostCSS plugin that lets you control your layout (LTR or RTL) through logical rather than physical rules
Stars: ✭ 18 (-83.33%)
Mutual labels:  postcss, postcss-plugins
Postcss Cssnext
`postcss-cssnext` has been deprecated in favor of `postcss-preset-env`.
Stars: ✭ 5,388 (+4888.89%)
Mutual labels:  postcss, postcss-plugins
Postcss Instagram
📷 PostCSS plugin for using Instagram filters in CSS
Stars: ✭ 111 (+2.78%)
Mutual labels:  postcss, postcss-plugins
Postcss At Rules Variables
PostCss plugin to use CSS Custom Properties in at-rule @each, @for, @if, @else and more...
Stars: ✭ 52 (-51.85%)
Mutual labels:  postcss, postcss-plugins
laggard
Automatically generate CSS fallbacks for legacy browsers, built on PostCSS
Stars: ✭ 23 (-78.7%)
Mutual labels:  postcss, postcss-plugins
Postcss Utilities
PostCSS plugin to add a collection of mixins, shortcuts, helpers and tools for your CSS
Stars: ✭ 293 (+171.3%)
Mutual labels:  postcss, postcss-plugins
Postcss Selector Not
PostCSS plugin to transform :not() W3C CSS level 4 pseudo class to more compatible CSS (multiple css3 :not() selectors)
Stars: ✭ 49 (-54.63%)
Mutual labels:  postcss, postcss-plugins
Postcss Font Family System Ui
PostCSS plugin to transform W3C CSS font-family: system-ui to a practical font-family list
Stars: ✭ 91 (-15.74%)
Mutual labels:  postcss, postcss-plugins
Voipussd
📞 IMEI (USSD) Library on Android Devices by @romellfudi
Stars: ✭ 97 (-10.19%)
Mutual labels:  accessibility
Ally.js
JavaScript library to help modern web applications with accessibility concerns
Stars: ✭ 1,447 (+1239.81%)
Mutual labels:  accessibility
Ember Cli Postcss
🔥 A Postcss integration for ember-cli
Stars: ✭ 97 (-10.19%)
Mutual labels:  postcss
Shortstack
🥞 minimal Rollup + PostCSS modern syntax starter template
Stars: ✭ 94 (-12.96%)
Mutual labels:  postcss

Build Status

PostCSS High Contrast

PostCSS High Contrast is PostCSS plugin that helps automatically convert all colors to high contrast. This Plugin gives you ability to create high contrast version of your project with ease.

Why?

Accessible websites are getting more popular. Some countries even pass laws obliging IT companies create high contrast versions of their projects. Creating high contrast version of your project due some reasons can be painful.

Live Example

Basic Usage

postcss([
	require('postcss-high-contrast')({
		aggressiveHC: true,
		aggressiveHCDefaultSelectorList: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'li', 'th', 'td'],
		aggressiveHCCustomSelectorList: ['div', 'span'],

		colorProps: ['color', 'fill'],

		backgroundColor: '#000',
		altBgColor: '#fff',

		textColor: '#fff',

		buttonSelector: ['button'],
		buttonColor: '#000',
		buttonBackgroundColor: '#fcff3c',
		buttonBorderColor: 'none',
		
		linkSelectors:  ['a'],
		linkColor: '#fcff3c',
		linkHoverColor: '#fcff3c',

		borderColor: '#fff',
		disableShadow: true,
		
		customSelectors: ['input'],
		customSelectorColor: '#fff',
		customSelectorBackgroundColor: '#000',
		customSelectorBorderdColor: '#fff',
		
		selectorsBlackList: ['textfield'],

		imageFilter: 'invert(100%)',
		imageSelectors: ['img'],

		removeCSSProps: false,
        CSSPropsWhiteList: ['background', 'background-color', 'color', 'border', 'border-top', 'border-bottom',
            'border-left', 'border-right', 'border-color', 'border-top-color', 'border-right-color',
            'border-bottom-color', 'border-left-color', 'box-shadow', 'filter', 'text-shadow', 'fill']
	})
]);

How It works?

None Aggressive Mode

PostCSS High Contrast plugin will find all colors and replace them to high contrast ones. input.css:

body {
	background: #fff;
	color: #000;
}

a {
	color: #0b39e1;
}

output.css:

body {
	background: #000;
	color: #fff;
}

a {
	color: #fcff3c;
}

Aggressive Mode

In addition to replacing colors to high contrast colors, there is "Aggressive Mode". "Aggressive Mode" (aggressiveHC) is enabled by default. If selector doesn't have color property it will automatically append it for increasing specificity and providing more accurate results. input.css:

h1 {
	font-size: 48px;
	margin: 0;
	padding: 0 24px;
	width: 100%;
}

p {
	font-size: 48px;
	margin: 0 0 24px;
}

output.css:

h1 {
	color: #fff;
	font-size: 48px;
	margin: 0;
	padding: 0 24px;
	width: 100%;
}

p {
	color: #fff;
	font-size: 48px;
	margin: 0 0 24px;
}

Use aggressiveHCDefaultSelectorList and aggressiveHCCustomSelectorList to define own lists of properties.

Removing Unused CSS

For better css optimization there is an option to remove unused css. input.css:

h1 {
	font-size: 48px;
	margin: 0;
	padding: 0 24px;
	width: 100%;
}

p {
	font-size: 48px;
	margin: 0 0 24px;
}

output.css:

h1 {
	color: #fff;
}

p {
	color: #fff;
}

For merging CSS selectors use CSS minifiers like CSSNano or CSSO. If you are using PostCSS High Contrast Plugins with some other PostCSS Plugins like PostCSS Increase Text Sizes you might need some other properties to remain. For this case there is CSSPropsWhiteList option that prevents from deleting css properties:

CSSPropsWhiteList: ['background', 'background-color', 'color', 'border', 'border-top', 'border-bottom', 'border-left', 'border-right', 'border-color', 'border-top-color', 'border-right-color', 'border-bottom-color', 'border-left-color', 'box-shadow', 'filter', 'text-shadow']

WARNING!

removeCSSProps also can remove css properies generated by PostCSS High Contrast. To Prevent this use CSSPropsWhiteList!

Appending to wepbage

Using this plugin it's better to generate new high contrast version of css file. Than it is very easy to add/append high contrast version css to a webpage using JavaScript. JQuery example:

function appendHighContrastCss(){
	var hc = '<link rel="stylesheet" href="/assets/css/high-contrast.css" id="hccss"/>';

	if(!$('#highContrastCss').length ){
		$('head').append(hc);
	} else {
		$('#hccss').remove();
	}
}

$('a.high-contrast').click(loadHighContrastCSS);
	appendHighContrastCss();
}

Tip: use cookies to remember turned on high contrast css on different sessions and pages.

Options

Name Default Value Description
aggressiveHC true Will append properties even if they do not exist
aggressiveHCDefaultSelectorList ['h1', 'h2', 'h3', 'h4', 'h5', 'h6','p', 'li', 'th', 'td'] Default list of selectors for aggressive property append
aggressiveHCCustomSelectorList ['span'] Custom list of selectors for aggressive property append
colorProps ['color','fill'] List of Properties that will be considered for color changing
backgroundColor #000 Backgound color
altBgColor #fff Alternative background color
textColor #fff Text color
buttonSelector [button] Button Selector
buttonColor #000 Button color
buttonBackgroundColor #fcff3c Button background color
buttonBorderColor none Button border color
linkColor #fcff3c Link color
linkHoverBgColor #fff Link hover bacground color
linkHoverColor #000 Link hover color
borderColor #fff Border color
disableShadow true Disable shadow
imageFilter false/invert(100%)/grayscale(100%)/contrast(200%) Image Filter (disabled by default). false to disable. Any css filter option can be passed
imageSelectors ['img'] Default list of image selectors to apply imageFilter
removeCSSProps false This option will remove all unused CSS selectors or properties for better optimization. Use CSS minifiers like CSSNano or CSSO to merge selectors
CSSPropsWhiteList ['background', 'background-color', 'color', 'border', 'border-top', 'border-bottom', 'border-left', 'border-right', 'border-color', 'border-top-color', 'border-right-color', 'border-bottom-color', 'border-left-color', 'box-shadow', 'filter', 'text-shadow'] CSS properties whitelist

Used by

Magyar Posta Signal IDUNA

Works great with:

PostCSS Increase Text Sizes

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].