No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

toCss.js 2.1 KiB

hace 3 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports['default'] = toCss;
  6. var _toCssValue = require('./toCssValue');
  7. var _toCssValue2 = _interopRequireDefault(_toCssValue);
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  9. /**
  10. * Indent a string.
  11. * http://jsperf.com/array-join-vs-for
  12. */
  13. function indentStr(str, indent) {
  14. var result = '';
  15. for (var index = 0; index < indent; index++) {
  16. result += ' ';
  17. }return result + str;
  18. }
  19. /**
  20. * Converts a Rule to CSS string.
  21. */
  22. function toCss(selector, style) {
  23. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  24. var result = '';
  25. if (!style) return result;
  26. var _options$indent = options.indent,
  27. indent = _options$indent === undefined ? 0 : _options$indent;
  28. var fallbacks = style.fallbacks;
  29. indent++;
  30. // Apply fallbacks first.
  31. if (fallbacks) {
  32. // Array syntax {fallbacks: [{prop: value}]}
  33. if (Array.isArray(fallbacks)) {
  34. for (var index = 0; index < fallbacks.length; index++) {
  35. var fallback = fallbacks[index];
  36. for (var prop in fallback) {
  37. var value = fallback[prop];
  38. if (value != null) {
  39. result += '\n' + indentStr(prop + ': ' + (0, _toCssValue2['default'])(value) + ';', indent);
  40. }
  41. }
  42. }
  43. } else {
  44. // Object syntax {fallbacks: {prop: value}}
  45. for (var _prop in fallbacks) {
  46. var _value = fallbacks[_prop];
  47. if (_value != null) {
  48. result += '\n' + indentStr(_prop + ': ' + (0, _toCssValue2['default'])(_value) + ';', indent);
  49. }
  50. }
  51. }
  52. }
  53. for (var _prop2 in style) {
  54. var _value2 = style[_prop2];
  55. if (_value2 != null && _prop2 !== 'fallbacks') {
  56. result += '\n' + indentStr(_prop2 + ': ' + (0, _toCssValue2['default'])(_value2) + ';', indent);
  57. }
  58. }
  59. // Allow empty style in this case, because properties will be added dynamically.
  60. if (!result && !options.allowEmpty) return result;
  61. indent--;
  62. result = indentStr(selector + ' {' + result + '\n', indent) + indentStr('}', indent);
  63. return result;
  64. }