clip.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. "use strict";
  2. // deprecated
  3. // @see https://drafts.fxtf.org/css-masking/#clip-property
  4. const parsers = require("../parsers");
  5. const strings = require("../utils/strings");
  6. module.exports.parse = function parse(v) {
  7. if (v === "") {
  8. return v;
  9. }
  10. const val = parsers.parseKeyword(v, ["auto"]);
  11. if (val) {
  12. return val;
  13. }
  14. // parse legacy <shape>
  15. v = strings.asciiLowercase(v);
  16. const matches = v.match(/^rect\(\s*(.*)\s*\)$/);
  17. if (!matches) {
  18. return;
  19. }
  20. const parts = matches[1].split(/\s*,\s*/);
  21. if (parts.length !== 4) {
  22. return;
  23. }
  24. const valid = parts.every(function (part, index) {
  25. const measurement = parsers.parseMeasurement(part.trim());
  26. parts[index] = measurement;
  27. return typeof measurement === "string";
  28. });
  29. if (!valid) {
  30. return;
  31. }
  32. return `rect(${parts.join(", ")})`;
  33. };
  34. module.exports.isValid = function isValid(v) {
  35. if (v === "") {
  36. return true;
  37. }
  38. return typeof module.exports.parse(v) === "string";
  39. };
  40. module.exports.definition = {
  41. set(v) {
  42. v = parsers.prepareValue(v, this._global);
  43. this._setProperty("clip", module.exports.parse(v));
  44. },
  45. get() {
  46. return this.getPropertyValue("clip");
  47. },
  48. enumerable: true,
  49. configurable: true
  50. };