cross-fade.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. 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; }
  4. 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) : subClass.__proto__ = superClass; }
  5. var Value = require('../value');
  6. var list = require('postcss/lib/list');
  7. var CrossFade = function (_Value) {
  8. _inherits(CrossFade, _Value);
  9. function CrossFade() {
  10. _classCallCheck(this, CrossFade);
  11. return _possibleConstructorReturn(this, _Value.apply(this, arguments));
  12. }
  13. CrossFade.prototype.replace = function replace(string, prefix) {
  14. var _this2 = this;
  15. return list.space(string).map(function (value) {
  16. if (value.slice(0, +_this2.name.length + 1) !== _this2.name + '(') {
  17. return value;
  18. }
  19. var close = value.lastIndexOf(')');
  20. var after = value.slice(close + 1);
  21. var args = value.slice(_this2.name.length + 1, close);
  22. if (prefix === '-webkit-') {
  23. var match = args.match(/\d*.?\d+%?/);
  24. if (match) {
  25. args = args.slice(match[0].length).trim();
  26. args += ', ' + match[0];
  27. } else {
  28. args += ', 0.5';
  29. }
  30. }
  31. return prefix + _this2.name + '(' + args + ')' + after;
  32. }).join(' ');
  33. };
  34. return CrossFade;
  35. }(Value);
  36. Object.defineProperty(CrossFade, 'names', {
  37. enumerable: true,
  38. writable: true,
  39. value: ['cross-fade']
  40. });
  41. module.exports = CrossFade;