pax_global_header00006660000000000000000000000064130451517250014515gustar00rootroot0000000000000052 comment=bb976831e7c6b0ed4a69fdfe547ed188c6f38f98 postcss-convert-values-2.6.1/000077500000000000000000000000001304515172500161745ustar00rootroot00000000000000postcss-convert-values-2.6.1/.all-contributorsrc000066400000000000000000000047041304515172500220320ustar00rootroot00000000000000{ "projectName": "postcss-convert-values", "projectOwner": "ben-eb", "files": [ "README.md" ], "imageSize": 100, "commit": false, "contributors": [ { "login": "ben-eb", "name": "Ben Briggs", "avatar_url": "https://avatars.githubusercontent.com/u/1282980?v=3", "profile": "http://beneb.info", "contributions": [ "code", "doc", "review", "test" ] }, { "login": "TrySound", "name": "Bogdan Chadkin", "avatar_url": "https://avatars.githubusercontent.com/u/5635476?v=3", "profile": "https://github.com/TrySound", "contributions": [ "code", "doc", "review", "test" ] }, { "login": "kizu", "name": "Roman Komarov", "avatar_url": "https://avatars.githubusercontent.com/u/177485?v=3", "profile": "http://kizu.ru/en/", "contributions": [ "bug" ] }, { "login": "dmitrykiselyov", "name": "Dmitry Kiselyov", "avatar_url": "https://avatars.githubusercontent.com/u/5103477?v=3", "profile": "http://codepen.io/dmitrykiselyov", "contributions": [ "bug" ] }, { "login": "tunnckoCore", "name": "Charlike Mike Reagent", "avatar_url": "https://avatars.githubusercontent.com/u/5038030?v=3", "profile": "http://www.tunnckocore.tk", "contributions": [ "code", "test" ] }, { "login": "Termina1", "name": "Vyacheslav Shebanov", "avatar_url": "https://avatars.githubusercontent.com/u/815848?v=3", "profile": "https://github.com/Termina1", "contributions": [ "doc" ] }, { "login": "marek-saji", "name": "Marek ‘saji’ Augustynowicz", "avatar_url": "https://avatars.githubusercontent.com/u/192323?v=3", "profile": "http://twitter.com/saji_", "contributions": [ "code", "test" ] }, { "login": "jgerigmeyer", "name": "Jonny Gerig Meyer", "avatar_url": "https://avatars.githubusercontent.com/u/552316?v=3", "profile": "www.oddbird.net", "contributions": [ "code", "test" ] }, { "login": "Justineo", "name": "GU Yiling", "avatar_url": "https://avatars.githubusercontent.com/u/1726061?v=3", "profile": "http://lync.in/", "contributions": [ "code", "test" ] } ] } postcss-convert-values-2.6.1/.babelrc000066400000000000000000000002321304515172500175640ustar00rootroot00000000000000{ "presets": ["es2015-loose", "stage-0"], "plugins": ["add-module-exports"], "env": { "development": { "sourceMaps": "inline" } } } postcss-convert-values-2.6.1/.editorconfig000066400000000000000000000003001304515172500206420ustar00rootroot00000000000000# editorconfig.org root = true [*] indent_style = space indent_size = 4 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.json] indent_size = 2 postcss-convert-values-2.6.1/.gitignore000066400000000000000000000000401304515172500201560ustar00rootroot00000000000000node_modules npm-debug.log dist postcss-convert-values-2.6.1/.travis.yml000066400000000000000000000003141304515172500203030ustar00rootroot00000000000000sudo: false language: node_js matrix: include: - node_js: '5' - node_js: '4' - node_js: '0.12' env: NO_ESLINT=true script: "[[ $NO_ESLINT == true ]] && npm run test-012 || npm test" postcss-convert-values-2.6.1/CHANGELOG.md000066400000000000000000000063671304515172500200210ustar00rootroot00000000000000# 2.6.1 * Resolves an issue where IE hacks were being removed from `0` values (thanks to @Justineo). # 2.6.0 * Added clamping of the values for the `shape-image-threshold` property, using the same logic as introduced in version `2.5.0`. # 2.5.0 * Added clamping of the values for the `opacity` property to the `0-1` range. For example, this will convert `opacity: 1.1` to `opacity: 1`. # 2.4.1 * Resolves an issue where the units would be stripped from zero values in custom properties (thanks to @jgerigmeyer). # 2.4.0 * Added a `precision` option to enable rounding of decimal places for `px` values. # 2.3.6 * Resolves an issue with the last patch where `height: 0em` was not being converted to `height: 0`. # 2.3.5 * Resolves an issue where certain properties inside `@keyframes` rules would break animation in IE due to the percentage being stripped. Now, the percentage is preserved for these properties. # 2.3.4 * Does not convert `height:0%` to `height:0` (and the same for `max-height`), as they produce different results. # 2.3.3 * Updates postcss-value-parser to version 3 (thanks to @TrySound). # 2.3.2 * Fixed a regression where `0%` in color functions was being transformed to `0` (thanks to @TrySound). # 2.3.1 * Fixed a behaviour where `0deg` was being converted to `0`. # 2.3.0 * Added an option to convert between `turn` & `deg` (thanks to @TrySound). # 2.2.1 * Fixes a behaviour where the module would remove units from zero values inside calc functions (thanks to @marek-saji & @TrySound). # 2.2.0 * Renames `opts.convertLength` & `opts.convertTime` to `opts.length` & `opts.time`; the old options will now print deprecation warnings (thanks to @TrySound). # 2.1.0 * Adds options to enable/disable unit conversion for time & length values. # 2.0.1 * Bump postcss-value-parser to `2.0.2`. # 2.0.0 * Upgraded to PostCSS 5. # 1.3.1 * Fixes an issue where the module would convert values in gradient/url functions since 1.3.0. # 1.3.0 * Converted the module to use ES6. * balanced-match, css-list & some integrated code has been replaced with postcss-value-parser; reducing the number of moving parts in this module, and providing a more futureproof way of parsing CSS numeric values. # 1.2.5 * Fixes an issue where uppercase units (such as PX) were being deleted. # 1.2.4 * Fixes convert not px or ms # 1.2.3 * Adds support for `ch` units; previously they were removed. * Upgrades css-list to `0.1.0`, code tidied up. # 1.2.2 * Added support for viewport units (thanks to @TrySound). # 1.2.1 * Fixes regressions introduced by the previous patch. Better support for negative value transforms. # 1.2.0 * Adds support for slash/comma separated values (thanks to @TrySound). # 1.1.1 * Fixes an issue where trailing zeroes were not being removed in values that were not `0` (thanks to @TrySound). # 1.1.0 * Adds support for removing leading zeroes from `rem` values (thanks to @tunnckoCore). # 1.0.3 * Fixed a bug where filenames were being incorrectly transformed. # 1.0.2 * Fixed a bug where `1.` and `.0` were not being optimised to `1` and `0`, respectively. # 1.0.1 * Fixed a bug where `undefined` would be stringified as the unit value, if the value did not have a unit. # 1.0.0 * Initial release. postcss-convert-values-2.6.1/LICENSE-MIT000066400000000000000000000021041304515172500176250ustar00rootroot00000000000000Copyright (c) Ben Briggs (http://beneb.info) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. postcss-convert-values-2.6.1/README.md000066400000000000000000000124041304515172500174540ustar00rootroot00000000000000# [postcss][postcss]-convert-values [![Build Status](https://travis-ci.org/ben-eb/postcss-convert-values.svg?branch=master)][ci] [![NPM version](https://badge.fury.io/js/postcss-convert-values.svg)][npm] [![Dependency Status](https://gemnasium.com/ben-eb/postcss-convert-values.svg)][deps] > Convert values with PostCSS (e.g. ms -> s) ## Install With [npm](https://npmjs.org/package/postcss-convert-values) do: ``` npm install postcss-convert-values --save ``` ## Example This plugin reduces CSS size by converting values to use different units where possible; for example, `500ms` can be represented as `.5s`. You can read more about these units in [this article][csstricks]. ### Input ```css h1 { font-size: 16px; width: 0em } ``` ### Output ```css h1 { font-size: 1pc; width: 0 } ``` Note that this plugin only covers conversions for duration and absolute length values. For color conversions, use [postcss-colormin][colormin]. ## API ### convertValues([options]) #### options ##### length Type: `boolean` Default: `true` Pass `false` to disable conversion from `px` to other absolute length units, such as `pc` & `pt` & vice versa. ##### time Type: `boolean` Default: `true` Pass `false` to disable conversion from `ms` to `s` & vice versa. ##### angle Type: `boolean` Default: `true` Pass `false` to disable conversion from `deg` to `turn` & vice versa. ##### precision Type: `boolean|number` Default: `false` Specify any numeric value here to round `px` values to that many decimal places; for example, using `{precision: 2}` will round `6.66667px` to `6.67px`, and `{precision: 0}` will round it to `7px`. Passing `false` (the default) will leave these values as is. It is recommended for most use cases to set this option to `2`. ## Contributors Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)): | [
Ben Briggs](http://beneb.info)
[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=ben-eb) [📖](https://github.com/ben-eb/postcss-convert-values/commits?author=ben-eb) 👀 [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=ben-eb) | [
Bogdan Chadkin](https://github.com/TrySound)
[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=TrySound) [📖](https://github.com/ben-eb/postcss-convert-values/commits?author=TrySound) 👀 [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=TrySound) | [
Roman Komarov](http://kizu.ru/en/)
[🐛](https://github.com/ben-eb/postcss-convert-values/issues?q=author%3Akizu) | [
Dmitry Kiselyov](http://codepen.io/dmitrykiselyov)
[🐛](https://github.com/ben-eb/postcss-convert-values/issues?q=author%3Admitrykiselyov) | [
Charlike Mike Reagent](http://www.tunnckocore.tk)
[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=tunnckoCore) [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=tunnckoCore) | [
Vyacheslav Shebanov](https://github.com/Termina1)
[📖](https://github.com/ben-eb/postcss-convert-values/commits?author=Termina1) | [
Marek ‘saji’ Augustynowicz](http://twitter.com/saji_)
[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=marek-saji) [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=marek-saji) | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | | [
Jonny Gerig Meyer](www.oddbird.net)
[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=jgerigmeyer) [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=jgerigmeyer) | [
GU Yiling](http://lync.in/)
[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=Justineo) [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=Justineo) | This project follows the [all-contributors] specification. Contributions of any kind welcome! ## License MIT © [Ben Briggs](http://beneb.info) [all-contributors]: https://github.com/kentcdodds/all-contributors [ci]: https://travis-ci.org/ben-eb/postcss-convert-values [colormin]: https://github.com/ben-eb/postcss-colormin [deps]: https://gemnasium.com/ben-eb/postcss-convert-values [npm]: http://badge.fury.io/js/postcss-convert-values [postcss]: https://github.com/postcss/postcss [csstricks]: https://css-tricks.com/the-lengths-of-css/ postcss-convert-values-2.6.1/package.json000066400000000000000000000027621304515172500204710ustar00rootroot00000000000000{ "name": "postcss-convert-values", "version": "2.6.1", "description": "Convert values with PostCSS (e.g. ms -> s)", "main": "dist/index.js", "files": [ "LICENSE-MIT", "dist" ], "scripts": { "contributorAdd": "all-contributors add", "contributorGenerate": "all-contributors generate", "pretest": "eslint src", "prepublish": "del-cli dist && BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/", "test": "ava", "test-012": "ava" }, "keywords": [ "css", "optimisation", "postcss", "postcss-plugin" ], "license": "MIT", "devDependencies": { "all-contributors-cli": "^3.0.5", "ava": "^0.17.0", "babel-cli": "^6.3.17", "babel-core": "^6.3.26", "babel-plugin-add-module-exports": "^0.2.1", "babel-preset-es2015": "^6.3.13", "babel-preset-es2015-loose": "^7.0.0", "babel-preset-stage-0": "^6.3.13", "babel-register": "^6.9.0", "del-cli": "^0.2.0", "eslint": "^3.0.0", "eslint-config-cssnano": "^3.0.0", "eslint-plugin-babel": "^3.3.0", "eslint-plugin-import": "^2.0.1" }, "homepage": "https://github.com/ben-eb/postcss-convert-values", "author": { "name": "Ben Briggs", "email": "beneb.info@gmail.com", "url": "http://beneb.info" }, "repository": "ben-eb/postcss-convert-values", "dependencies": { "postcss": "^5.0.11", "postcss-value-parser": "^3.1.2" }, "ava": { "require": "babel-register" }, "eslintConfig": { "extends": "cssnano" } } postcss-convert-values-2.6.1/src/000077500000000000000000000000001304515172500167635ustar00rootroot00000000000000postcss-convert-values-2.6.1/src/__tests__/000077500000000000000000000000001304515172500207215ustar00rootroot00000000000000postcss-convert-values-2.6.1/src/__tests__/index.js000066400000000000000000000252571304515172500224010ustar00rootroot00000000000000import test from 'ava'; import postcss from 'postcss'; import plugin from '..'; import {name} from '../../package.json'; const suites = [{ message: 'should convert milliseconds to seconds', fixture: 'h1{transition-duration:500ms}', expected: 'h1{transition-duration:.5s}', }, { message: 'should convert seconds to milliseconds', fixture: 'h1{transition-duration:.005s}', expected: 'h1{transition-duration:5ms}', }, { message: 'should not convert negative milliseconds to seconds', fixture: 'h1{animation-duration:-569ms}', expected: 'h1{animation-duration:-569ms}', }, { message: 'should not remove the unit from zero values (duration)', fixture: 'h1{transition-duration:0s}', expected: 'h1{transition-duration:0s}', }, { message: 'should not remove the unit from zero values (custom properties)', fixture: 'h1{--my-variable:0px}', expected: 'h1{--my-variable:0px}', }, { message: 'should remove unnecessary plus signs', fixture: 'h1{width:+14px}', expected: 'h1{width:14px}', }, { message: 'should convert px to pc', fixture: 'h1{width:16px}', expected: 'h1{width:1pc}', }, { message: 'should convert px to pt', fixture: 'h1{width:120px}', expected: 'h1{width:90pt}', }, { message: 'should convert px to in', fixture: 'h1{width:192px}', expected: 'h1{width:2in}', }, { message: 'should not convert in to px', fixture: 'h1{width:192in}', expected: 'h1{width:192in}', }, { message: 'should strip the units from length properties', fixture: 'h1{margin: 0em 0% 0px 0pc}', expected: 'h1{margin: 0 0 0 0}', }, { message: 'should trim trailing zeros', fixture: 'h1{width:109.00000000000px}', expected: 'h1{width:109px}', }, { message: 'should trim trailing zeros + unit', fixture: 'h1{width:0.00px}', expected: 'h1{width:0}', }, { message: 'should trim trailing zeros without unit', fixture: 'h1{width:100.00%}', expected: 'h1{width:100%}', }, { message: 'should not mangle flex basis', fixture: 'h1{flex-basis:0%}', expected: 'h1{flex-basis:0%}', }, { message: 'should not mangle values without units', fixture: 'h1{z-index:5}', expected: 'h1{z-index:5}', }, { message: 'should operate in calc values', fixture: 'h1{width:calc(192px + 2em - (0px * 4))}', expected: 'h1{width:calc(2in + 2em - (0px * 4))}', }, { message: 'should not convert zero values in calc', fixture: 'h1{width:calc(0em)}', expected: 'h1{width:calc(0em)}', }, { message: 'should not mangle values outside of its domain', fixture: 'h1{background:url(a.png)}', expected: 'h1{background:url(a.png)}', }, { message: 'should optimise fractions', fixture: 'h1{opacity:1.}h2{opacity:.0}', expected: 'h1{opacity:1}h2{opacity:0}', }, { message: 'should optimise fractions with units', fixture: 'h1{width:10.px}h2{width:.0px}', expected: 'h1{width:10px}h2{width:0}', }, { message: 'should optimise fractions inside calc', fixture: 'h1{width:calc(10.px + .0px)}', expected: 'h1{width:calc(10px + 0px)}', }, { message: 'should handle leading zero in rem values', fixture: '.one{top:0.25rem}', expected: '.one{top:.25rem}', }, { message: 'should handle slash separated values', fixture: '.one{background: 50% .0%/100.0% 100.0%}', expected: '.one{background: 50% 0/100% 100%}', }, { message: 'should handle comma separated values', fixture: '.one{background: 50% .0% ,100.0% 100.0%}', expected: '.one{background: 50% 0 ,100% 100%}', }, { message: 'should not mangle duration values', fixture: '.long{animation-duration:2s}', expected: '.long{animation-duration:2s}', }, { message: 'should not mangle padding values', fixture: 'h1{padding:10px 20px 30px 40px}h2{padding:10px 20px 30px}h3{padding:10px 20px}h4{padding:10px}', expected: 'h1{padding:10px 20px 30px 40px}h2{padding:10px 20px 30px}h3{padding:10px 20px}h4{padding:10px}', }, { message: 'should trim leading zeroes from negative values', fixture: 'h1,h2{letter-spacing:-0.1rem}', expected: 'h1,h2{letter-spacing:-.1rem}', }, { message: 'should support viewports units', fixture: 'h1,h2{letter-spacing:-0.1vmin}', expected: 'h1,h2{letter-spacing:-.1vmin}', }, { message: 'should support ch units', fixture: 'a{line-height:1.1ch}', expected: 'a{line-height:1.1ch}', }, { message: 'should support PX units', fixture: 'h1{font-size:20PX}', expected: 'h1{font-size:20px}', }, { message: 'should not mangle data urls', fixture: '.has-svg:before{content:url("data:image/svg+xml;utf8,")}', expected: '.has-svg:before{content:url("data:image/svg+xml;utf8,")}', }, { message: 'should convert angle units', fixture: 'h1{transform: rotate(0.25turn);transform: rotate(0.25TURN)}', expected: 'h1{transform: rotate(90deg);transform: rotate(90deg)}', }, { message: 'should not convert length units', fixture: 'h1{transition-duration:500ms; width:calc(192px + 2em); width:+14px; letter-spacing:-0.1VMIN}', expected: 'h1{transition-duration:.5s; width:calc(192px + 2em); width:14px; letter-spacing:-.1vmin}', options: {length: false}, }, { message: 'should not convert time units', fixture: 'h1{transition-duration:500ms; width:calc(192px + 2em); width:+14px; letter-spacing:-0.1VMIN}', expected: 'h1{transition-duration:500ms; width:calc(2in + 2em); width:14px; letter-spacing:-.1vmin}', options: {time: false}, }, { message: 'should not convert angle units', fixture: 'h1{transform: rotate(0.25turn);transform: rotate(0.25TURN)}', expected: 'h1{transform: rotate(.25turn);transform: rotate(.25turn)}', options: {angle: false}, }, { message: 'should not convert length units with deprecated option', fixture: 'h1{transition-duration:500ms; width:calc(192px + 2em); width:+14px; letter-spacing:-0.1VMIN}', expected: 'h1{transition-duration:.5s; width:calc(192px + 2em); width:14px; letter-spacing:-.1vmin}', options: {convertLength: false}, }, { message: 'should not convert time units with deprecated option', fixture: 'h1{transition-duration:500ms; width:calc(192px + 2em); width:+14px; letter-spacing:-0.1VMIN}', expected: 'h1{transition-duration:500ms; width:calc(2in + 2em); width:14px; letter-spacing:-.1vmin}', options: {convertTime: false}, }, { message: 'should not remove units from angle values', fixture: 'h1{transform:rotate(0deg)}', expected: 'h1{transform:rotate(0deg)}', }, { message: 'should not remove units from angle values (2)', fixture: 'h1{transform:rotate(0turn)}', expected: 'h1{transform:rotate(0turn)}', }, { message: 'should not remove unit with zero value in hsl and hsla functions', fixture: 'h1{color:hsl(0, 0%, 244%); background:hsl(0, 0%, 0%)}', expected: 'h1{color:hsl(0, 0%, 244%); background:hsl(0, 0%, 0%)}', }, { message: 'should strip trailing zeroes from percentage heights', fixture: 'h1{height:12.500%}', expected: 'h1{height:12.5%}', }, { message: 'should not strip the percentage from 0 in max-height & height props', fixture: 'h1{height:0%;max-height:0%}', expected: 'h1{height:0%;max-height:0%}', }, { message: 'should not crash when analysing a declaration with one parent', fixture: 'width:0', expected: 'width:0', }, { message: 'should strip the unit from 0 in max-height & height props', fixture: 'h1{height:0em;max-height:0em}', expected: 'h1{height:0;max-height:0}', }, { message: 'should round pixel values to two decimal places', fixture: 'h1{right:6.66667px}', expected: 'h1{right:6.67px}', options: { precision: 2, }, }, { message: 'should round pixel values with customisable precision', fixture: 'h1{right:6.66667px}', expected: 'h1{right:7px}', options: { precision: 0, }, }, { message: 'should not round pixel values to two decimal places by default', fixture: 'h1{right:6.66667px}', expected: 'h1{right:6.66667px}', }, { message: 'should clamp opacity to 1 maximum', fixture: 'h1{opacity:150;opacity:15;opacity:1.5}', expected: 'h1{opacity:1;opacity:1;opacity:1}', }, { message: 'should clamp opacity to 0 minimum', fixture: 'h1{opacity:-0.5;opacity:-5;opacity:-50}', expected: 'h1{opacity:0;opacity:0;opacity:0}', }, { message: 'should keep stripping zeroes from opacity', fixture: 'h1{opacity:0.0625}', expected: 'h1{opacity:.0625}', }, { message: 'should clamp shape-image-threshold to 1 maximum', fixture: 'h1{shape-image-threshold:150;shape-image-threshold:15;shape-image-threshold:1.5}', expected: 'h1{shape-image-threshold:1;shape-image-threshold:1;shape-image-threshold:1}', }, { message: 'should clamp shape-image-threshold to 0 minimum', fixture: 'h1{shape-image-threshold:-0.5;shape-image-threshold:-5;shape-image-threshold:-50}', expected: 'h1{shape-image-threshold:0;shape-image-threshold:0;shape-image-threshold:0}', }, { message: 'should keep stripping zeroes from shape-image-threshold', fixture: 'h1{shape-image-threshold:0.0625}', expected: 'h1{shape-image-threshold:.0625}', }, { message: 'should keep unknown units or hacks', fixture: 'h1{top:0\\9\\0;left:0lightyear}', expected: 'h1{top:0\\9\\0;left:0lightyear}', }]; ['stroke-dasharray', 'stroke-dashoffset', 'stroke-width'].forEach(property => { suites.push({ message: `should not strip the percentage from 0 in SVG animation, for IE (${property})`, fixture: `@keyframes a{0%{${property}:200%}to{${property}:0%}}`, expected: `@keyframes a{0%{${property}:200%}to{${property}:0%}}`, }); }); suites.forEach(({message, fixture, expected, options = {}}) => { test(message, t => { return postcss(plugin(options)).process(fixture).then(({css}) => { t.deepEqual(css, expected); }); }); }); test('should use the postcss plugin api', t => { t.plan(2); t.truthy(plugin().postcssVersion, 'should be able to access version'); t.deepEqual(plugin().postcssPlugin, name, 'should be able to access name'); }); postcss-convert-values-2.6.1/src/index.js000066400000000000000000000062651304515172500204410ustar00rootroot00000000000000import postcss from 'postcss'; import valueParser, {unit, walk} from 'postcss-value-parser'; import convert from './lib/convert'; const LENGTH_UNITS = [ 'em', 'ex', 'ch', 'rem', 'vw', 'vh', 'vmin', 'vmax', 'cm', 'mm', 'q', 'in', 'pt', 'pc', 'px', ]; function parseWord (node, opts, keepZeroUnit) { const pair = unit(node.value); if (pair) { const num = Number(pair.number); const u = pair.unit.toLowerCase(); if (num === 0) { node.value = ( keepZeroUnit || !~LENGTH_UNITS.indexOf(u) && u !== '%' ) ? 0 + u : 0; } else { node.value = convert(num, u, opts); if ( typeof opts.precision === 'number' && u === 'px' && ~pair.number.indexOf('.') ) { const precision = Math.pow(10, opts.precision); node.value = Math.round(parseFloat(node.value) * precision) / precision + u; } } } } function clampOpacity (node) { const pair = unit(node.value); if (!pair) { return; } let num = Number(pair.number); if (num > 1) { node.value = 1 + pair.unit; } else if (num < 0) { node.value = 0 + pair.unit; } } function shouldStripPercent ({value, prop, parent}) { return ~value.indexOf('%') && (prop === 'max-height' || prop === 'height') || parent.parent && parent.parent.name === 'keyframes' && prop === 'stroke-dasharray' || prop === 'stroke-dashoffset' || prop === 'stroke-width'; } function transform (opts) { return decl => { const {prop} = decl; if (~prop.indexOf('flex') || prop.indexOf('--') === 0) { return; } decl.value = valueParser(decl.value).walk(node => { if (node.type === 'word') { parseWord(node, opts, shouldStripPercent(decl)); if (prop === 'opacity' || prop === 'shape-image-threshold') { clampOpacity(node); } } else if (node.type === 'function') { if (node.value === 'calc' || node.value === 'hsl' || node.value === 'hsla') { walk(node.nodes, n => { if (n.type === 'word') { parseWord(n, opts, true); } }); return false; } if (node.value === 'url') { return false; } } }).toString(); }; } const plugin = 'postcss-convert-values'; export default postcss.plugin(plugin, (opts = {precision: false}) => { if (opts.length === undefined && opts.convertLength !== undefined) { console.warn(`${plugin}: \`convertLength\` option is deprecated. Use \`length\``); opts.length = opts.convertLength; } if (opts.length === undefined && opts.convertTime !== undefined) { console.warn(`${plugin}: \`convertTime\` option is deprecated. Use \`time\``); opts.time = opts.convertTime; } return css => css.walkDecls(transform(opts)); }); postcss-convert-values-2.6.1/src/lib/000077500000000000000000000000001304515172500175315ustar00rootroot00000000000000postcss-convert-values-2.6.1/src/lib/convert.js000066400000000000000000000030441304515172500215500ustar00rootroot00000000000000const lengthConv = { in: 96, px: 1, pt: 4 / 3, pc: 16, }; const timeConv = { s: 1000, ms: 1, }; const angleConv = { turn: 360, deg: 1, }; function dropLeadingZero (number) { const value = String(number); if (number % 1) { if (value[0] === '0') { return value.slice(1); } if (value[0] === '-' && value[1] === '0') { return '-' + value.slice(2); } } return value; } function transform (number, unit, conversion) { let one, base; let convertionUnits = Object.keys(conversion).filter(u => { if (conversion[u] === 1) { one = u; } return unit !== u; }); if (unit === one) { base = number / conversion[unit]; } else { base = number * conversion[unit]; } return convertionUnits .map(u => dropLeadingZero(base / conversion[u]) + u) .reduce((a, b) => a.length < b.length ? a : b); } export default function (number, unit, {time, length, angle}) { let value = dropLeadingZero(number) + (unit ? unit : ''); let converted; if (length !== false && unit in lengthConv) { converted = transform(number, unit, lengthConv); } if (time !== false && unit in timeConv) { converted = transform(number, unit, timeConv); } if (angle !== false && unit in angleConv) { converted = transform(number, unit, angleConv); } if (converted && converted.length < value.length) { value = converted; } return value; }