cross-fade.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. 'use strict';
  2. function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
  3. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  5. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); }
  6. var Value = require('../value');
  7. var list = require('postcss').list;
  8. var CrossFade = function (_Value) {
  9. _inherits(CrossFade, _Value);
  10. function CrossFade() {
  11. _classCallCheck(this, CrossFade);
  12. return _possibleConstructorReturn(this, _Value.apply(this, arguments));
  13. }
  14. CrossFade.prototype.replace = function replace(string, prefix) {
  15. var _this2 = this;
  16. return list.space(string).map(function (value) {
  17. if (value.slice(0, +_this2.name.length + 1) !== _this2.name + '(') {
  18. return value;
  19. }
  20. var close = value.lastIndexOf(')');
  21. var after = value.slice(close + 1);
  22. var args = value.slice(_this2.name.length + 1, close);
  23. if (prefix === '-webkit-') {
  24. var match = args.match(/\d*.?\d+%?/);
  25. if (match) {
  26. args = args.slice(match[0].length).trim();
  27. args += ', ' + match[0];
  28. } else {
  29. args += ', 0.5';
  30. }
  31. }
  32. return prefix + _this2.name + '(' + args + ')' + after;
  33. }).join(' ');
  34. };
  35. return CrossFade;
  36. }(Value);
  37. Object.defineProperty(CrossFade, 'names', {
  38. enumerable: true,
  39. writable: true,
  40. value: ['cross-fade']
  41. });
  42. module.exports = CrossFade;