clip.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use strict';
  2. var parseMeasurement = require('../parsers').parseMeasurement;
  3. var shape_regex = /^rect\((.*)\)$/i;
  4. var parse = function(val) {
  5. if (val === '' || val === null) {
  6. return val;
  7. }
  8. if (typeof val !== 'string') {
  9. return undefined;
  10. }
  11. val = val.toLowerCase();
  12. if (val === 'auto' || val === 'inherit') {
  13. return val;
  14. }
  15. var matches = val.match(shape_regex);
  16. if (!matches) {
  17. return undefined;
  18. }
  19. var parts = matches[1].split(/\s*,\s*/);
  20. if (parts.length !== 4) {
  21. return undefined;
  22. }
  23. var valid = parts.every(function(part, index) {
  24. var measurement = parseMeasurement(part);
  25. parts[index] = measurement;
  26. return measurement !== undefined;
  27. });
  28. if (!valid) {
  29. return undefined;
  30. }
  31. parts = parts.join(', ');
  32. return val.replace(matches[1], parts);
  33. };
  34. module.exports.definition = {
  35. set: function(v) {
  36. this._setProperty('clip', parse(v));
  37. },
  38. get: function() {
  39. return this.getPropertyValue('clip');
  40. },
  41. enumerable: true,
  42. configurable: true,
  43. };