選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. # Autoprefixer for Style Objects
  2. **inline-style-prefixer** adds required **vendor prefixes** to your style object. It only adds prefixes if they're actually required by evaluating the browser's `userAgent` against data from [caniuse.com](http://caniuse.com/).
  3. <br>
  4. Alternatively it ships a static version that adds all available vendor prefixes.
  5. [![Build Status](https://travis-ci.org/rofrischmann/inline-style-prefixer.svg)](https://travis-ci.org/rofrischmann/inline-style-prefixer)
  6. [![Test Coverage](https://codeclimate.com/github/rofrischmann/inline-style-prefixer/badges/coverage.svg)](https://codeclimate.com/github/rofrischmann/inline-style-prefixer/coverage)
  7. [![npm downloads](https://img.shields.io/npm/dm/inline-style-prefixer.svg)](https://img.shields.io/npm/dm/inline-style-prefixer.svg)
  8. ![Dependencies](https://david-dm.org/rofrischmann/inline-style-prefixer.svg)
  9. ## Installation
  10. ```sh
  11. yarn add inline-style-prefixer
  12. ```
  13. If you're still using npm, you may run `npm i --save inline-style-prefixer`.
  14. We also provide [UMD](https://github.com/umdjs/umd) builds for each package in the `dist` folder. You can easily use them via [unpkg](https://unpkg.com/).
  15. ```HTML
  16. <!-- Unminified versions -->
  17. <script src="https://unpkg.com/inline-style-prefixer@3.0.1/dist/inline-style-prefixer.js"></script>
  18. <script src="https://unpkg.com/inline-style-prefixer@3.0.1/dist/inline-style-prefix-all.js"></script>
  19. <!-- Minified versions -->
  20. <script src="https://unpkg.com/inline-style-prefixer@3.0.1/dist/inline-style-prefixer.min.js"></script>
  21. <script src="https://unpkg.com/inline-style-prefixer@3.0.1/dist/inline-style-prefix-all.min.js"></script>
  22. ```
  23. ## Browser Support
  24. It supports all major browsers with the following versions. For other, unsupported browses, we automatically use a fallback.
  25. * Chrome: 46+
  26. * Android (Chrome): 46+
  27. * Android (Stock Browser): 4+
  28. * Android (UC): 9+
  29. * Firefox: 40+
  30. * Safari: 8+
  31. * iOS (Safari): 8+
  32. * Opera: 16+
  33. * Opera (Mini): 12+
  34. * IE: 11+
  35. * IE (Mobile): 11+
  36. * Edge: 12+
  37. It will **only** add prefixes if a property still needs them in one of the above mentioned versions.<br> Therefore, e.g. `border-radius` will not be prefixed at all.
  38. > **Need to support legacy browser versions?**<br>
  39. Don't worry - we got you covered. Check [this guide](https://github.com/rofrischmann/inline-style-prefixer/blob/master/docs/guides/CustomPrefixer.md).
  40. ## Dynamic vs. Static
  41. Before using the prefixer, you have to decide which one you want to use. We ship two different versions - a dynamic and a static version.
  42. The **dynamic prefixer** evaluates the `userAgent` to identify the browser environment. Using this technique, we are able to only add the bare minimum of prefixes. Browser detection is quite accurate (~90% correctness), but yet also expensive which is why the package is almost 3 times as big as the static version.
  43. > It uses the static prefixer as a fallback.
  44. ![Gzipped Size](https://img.shields.io/badge/gzipped-8.50kb-brightgreen.svg)
  45. ```javascript
  46. import Prefixer from 'inline-style-prefixer'
  47. const style = {
  48. transition: '200ms all linear',
  49. userSelect: 'none',
  50. boxSizing: 'border-box',
  51. display: 'flex',
  52. color: 'blue'
  53. }
  54. const prefixer = new Prefixer()
  55. const prefixedStyle = prefixer.prefix(style)
  56. // prefixedStyle === output
  57. const output = {
  58. transition: '200ms all linear',
  59. WebkitUserSelect: 'none',
  60. boxSizing: 'border-box',
  61. display: '-webkit-flex',
  62. color: 'blue'
  63. }
  64. ```
  65. The **static prefixer**, on the other hand, adds all required prefixes according the above mentioned browser versions. Removing the browser detection makes it both smaller and fast, but also drastically increases the output.
  66. ![Gzipped Size](https://img.shields.io/badge/gzipped-2.70kb-brightgreen.svg)
  67. ```javascript
  68. import prefixAll from 'inline-style-prefixer/static'
  69. const style = {
  70. transition: '200ms all linear',
  71. boxSizing: 'border-box',
  72. display: 'flex',
  73. color: 'blue'
  74. }
  75. const prefixedStyle = prefixAll(style)
  76. // prefixedStyle === output
  77. const output = {
  78. WebkitTransition: '200ms all linear',
  79. transition: '200ms all linear',
  80. MozBoxSizing: 'border-box',
  81. boxSizing: 'border-box',
  82. display: [ '-webkit-box', '-moz-box', '-ms-flexbox', '-webkit-flex', 'flex' ]
  83. color: 'blue'
  84. }
  85. ```
  86. ## Usage with TypeScript
  87. You can use TypeScript definition from [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/inline-style-prefixer) using [@types/inline-style-prefixer](https://www.npmjs.com/package/@types/inline-style-prefixer)
  88. ```sh
  89. npm install --save @types/inline-style-prefixer
  90. ```
  91. Then import in your code:
  92. ```typescript
  93. import prefixAll = require('inline-style-prefixer/static');
  94. const prefixedStyle = prefixAll({
  95. transition: '200ms all linear',
  96. boxSizing: 'border-box',
  97. display: 'flex',
  98. color: 'blue'
  99. });
  100. ```
  101. ## Documentation
  102. If you got any issue using this prefixer, please first check the FAQ's. Most cases are already covered and provide a solid solution.
  103. * [Usage Guides](https://inline-style-prefixer.js.org/docs/UsageGuides.html)
  104. * [Data Reference](https://inline-style-prefixer.js.org/docs/DataReference.html)
  105. * [API Reference](https://inline-style-prefixer.js.org/docs/API.html)
  106. * [FAQ](https://inline-style-prefixer.js.org/docs/FAQ.html)
  107. ## Community
  108. Here are some popular users of this library:
  109. * [Aphrodite](https://github.com/Khan/aphrodite)
  110. * [Fela](https://github.com/rofrischmann/fela)
  111. * [Glamor](https://github.com/threepointone/glamor)
  112. * [Material UI](https://github.com/callemall/material-ui)
  113. * [Radium](https://github.com/FormidableLabs/radium)
  114. * [react-native-web](https://github.com/necolas/react-native-web)
  115. * [styled-components](https://github.com/styled-components/styled-components)
  116. * [Styletron](https://github.com/rtsao/styletron)
  117. > PS: Feel free to add your solution!
  118. ## Support
  119. Join us on [Gitter](https://gitter.im/rofrischmann/fela). We highly appreciate any contribution.<br>
  120. We also love to get feedback.
  121. ## License
  122. **inline-style-prefixer** is licensed under the [MIT License](http://opensource.org/licenses/MIT).<br>
  123. Documentation is licensed under [Creative Common License](http://creativecommons.org/licenses/by/4.0/).<br>
  124. Created with ♥ by [@rofrischmann](http://rofrischmann.de) and all contributors.