You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

47 lines
1.5 KiB

  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  6. exports['default'] = cloneStyle;
  7. var _isObservable = require('./isObservable');
  8. var _isObservable2 = _interopRequireDefault(_isObservable);
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  10. var isArray = Array.isArray;
  11. function cloneStyle(style) {
  12. // Support empty values in case user ends up with them by accident.
  13. if (style == null) return style;
  14. // Support string value for SimpleRule.
  15. var typeOfStyle = typeof style === 'undefined' ? 'undefined' : _typeof(style);
  16. if (typeOfStyle === 'string' || typeOfStyle === 'number' || typeOfStyle === 'function') {
  17. return style;
  18. }
  19. // Support array for FontFaceRule.
  20. if (isArray(style)) return style.map(cloneStyle);
  21. // Support Observable styles. Observables are immutable, so we don't need to
  22. // copy them.
  23. if ((0, _isObservable2['default'])(style)) return style;
  24. var newStyle = {};
  25. for (var name in style) {
  26. var value = style[name];
  27. if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') {
  28. newStyle[name] = cloneStyle(value);
  29. continue;
  30. }
  31. newStyle[name] = value;
  32. }
  33. return newStyle;
  34. }