Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

69 строки
2.1 KiB

  1. 'use strict';
  2. const browserslist = require('browserslist');
  3. const { isSupported } = require('caniuse-api');
  4. const fromInitial = require('./data/fromInitial.json');
  5. const toInitial = require('./data/toInitial.json');
  6. const initial = 'initial';
  7. // In most of the browser including chrome the initial for `writing-mode` is not `horizontal-tb`. Ref https://github.com/cssnano/cssnano/pull/905
  8. const defaultIgnoreProps = ['writing-mode', 'transform-box'];
  9. /**
  10. * @type {import('postcss').PluginCreator<void>}
  11. * @return {import('postcss').Plugin}
  12. */
  13. function pluginCreator() {
  14. return {
  15. postcssPlugin: 'postcss-reduce-initial',
  16. /** @param {import('postcss').Result & {opts: browserslist.Options & {ignore?: string[]}}} result */
  17. prepare(result) {
  18. const resultOpts = result.opts || {};
  19. const browsers = browserslist(null, {
  20. stats: resultOpts.stats,
  21. path: __dirname,
  22. env: resultOpts.env,
  23. });
  24. const initialSupport = isSupported('css-initial-value', browsers);
  25. return {
  26. OnceExit(css) {
  27. css.walkDecls((decl) => {
  28. const lowerCasedProp = decl.prop.toLowerCase();
  29. const ignoreProp = new Set(
  30. defaultIgnoreProps.concat(resultOpts.ignore || [])
  31. );
  32. if (ignoreProp.has(lowerCasedProp)) {
  33. return;
  34. }
  35. if (
  36. initialSupport &&
  37. Object.prototype.hasOwnProperty.call(toInitial, lowerCasedProp) &&
  38. decl.value.toLowerCase() ===
  39. toInitial[/** @type {keyof toInitial} */ (lowerCasedProp)]
  40. ) {
  41. decl.value = initial;
  42. return;
  43. }
  44. if (
  45. decl.value.toLowerCase() !== initial ||
  46. !fromInitial[/** @type {keyof fromInitial} */ (lowerCasedProp)]
  47. ) {
  48. return;
  49. }
  50. decl.value =
  51. fromInitial[/** @type {keyof fromInitial} */ (lowerCasedProp)];
  52. });
  53. },
  54. };
  55. },
  56. };
  57. }
  58. pluginCreator.postcss = true;
  59. module.exports = pluginCreator;