cross-fade.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. (function() {
  2. var CrossFade, OldValue, Value, list, utils,
  3. extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  4. hasProp = {}.hasOwnProperty;
  5. OldValue = require('../old-value');
  6. Value = require('../value');
  7. utils = require('../utils');
  8. list = require('postcss/lib/list');
  9. CrossFade = (function(superClass) {
  10. extend(CrossFade, superClass);
  11. function CrossFade() {
  12. return CrossFade.__super__.constructor.apply(this, arguments);
  13. }
  14. CrossFade.names = ['cross-fade'];
  15. CrossFade.prototype.replace = function(string, prefix) {
  16. return list.space(string).map((function(_this) {
  17. return function(value) {
  18. var after, args, close, match;
  19. if (value.slice(0, +_this.name.length + 1 || 9e9) !== _this.name + '(') {
  20. return value;
  21. }
  22. close = value.lastIndexOf(')');
  23. after = value.slice(close + 1);
  24. args = value.slice(_this.name.length + 1, +(close - 1) + 1 || 9e9);
  25. if (prefix === '-webkit-') {
  26. match = args.match(/\d*.?\d+%?/);
  27. if (match) {
  28. args = args.slice(match[0].length).trim();
  29. args += ', ' + match[0];
  30. } else {
  31. args += ', 0.5';
  32. }
  33. }
  34. return prefix + _this.name + '(' + args + ')' + after;
  35. };
  36. })(this)).join(' ');
  37. };
  38. return CrossFade;
  39. })(Value);
  40. module.exports = CrossFade;
  41. }).call(this);