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

74 строки
1.6 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _util = require("./util");
  7. // Inspired by https://github.com/reactjs/react-magic/blob/master/src/htmltojsx.js
  8. /**
  9. * Determines if the CSS value can be converted from a
  10. * 'px' suffixed string to a numeric value.
  11. *
  12. * @param {string} value CSS property value
  13. * @return {boolean}
  14. */
  15. function isConvertiblePixelValue(value) {
  16. return /^\d+px$/.test(value);
  17. }
  18. /**
  19. * Format style key into JSX style object key.
  20. *
  21. * @param {string} key
  22. * @return {string}
  23. */
  24. function formatKey(key) {
  25. key = key.toLowerCase(); // Don't capitalize -ms- prefix
  26. if (/^-ms-/.test(key)) key = key.substr(1);
  27. return (0, _util.hyphenToCamelCase)(key);
  28. }
  29. /**
  30. * Format style value into JSX style object value.
  31. *
  32. * @param {string} key
  33. * @return {string}
  34. */
  35. function formatValue(value) {
  36. if ((0, _util.isNumeric)(value)) return Number(value);
  37. if (isConvertiblePixelValue(value)) return Number((0, _util.trimEnd)(value, 'px'));
  38. return value;
  39. }
  40. /**
  41. * Handle parsing of inline styles.
  42. *
  43. * @param {string} rawStyle
  44. * @returns {object}
  45. */
  46. function stringToObjectStyle(rawStyle) {
  47. const entries = rawStyle.split(';');
  48. return entries.reduce((styles, style) => {
  49. style = style.trim();
  50. const firstColon = style.indexOf(':');
  51. const value = style.substr(firstColon + 1).trim();
  52. const key = style.substr(0, firstColon);
  53. if (key !== '') {
  54. styles[formatKey(key)] = formatValue(value);
  55. }
  56. return styles;
  57. }, {});
  58. }
  59. var _default = stringToObjectStyle;
  60. exports.default = _default;