fontVariant.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. "use strict";
  2. const parsers = require("../parsers");
  3. const property = "font-variant";
  4. const shorthand = "font";
  5. module.exports.parse = (v, opt = {}) => {
  6. const { globalObject } = opt;
  7. if (v === "") {
  8. return v;
  9. }
  10. const values = parsers.splitValue(v);
  11. const parsedValues = [];
  12. for (const val of values) {
  13. const value = parsers.parsePropertyValue(property, val, {
  14. globalObject,
  15. inArray: true
  16. });
  17. if (Array.isArray(value) && value.length === 1) {
  18. const parsedValue = parsers.resolveFunctionValue(value);
  19. if (!parsedValue) {
  20. return;
  21. }
  22. parsedValues.push(parsedValue);
  23. } else if (typeof value === "string") {
  24. parsedValues.push(value);
  25. }
  26. }
  27. if (parsedValues.length) {
  28. if (parsedValues.length > 1) {
  29. if (parsedValues.includes("normal") || parsedValues.includes("none")) {
  30. return;
  31. }
  32. }
  33. return parsedValues.join(" ");
  34. }
  35. };
  36. module.exports.definition = {
  37. set(v) {
  38. v = parsers.prepareValue(v);
  39. if (parsers.hasVarFunc(v)) {
  40. this._setProperty(shorthand, "");
  41. this._setProperty(property, v);
  42. } else {
  43. const val = module.exports.parse(v, {
  44. globalObject: this._global
  45. });
  46. if (typeof val === "string") {
  47. const priority =
  48. !this._priorities.get(shorthand) && this._priorities.has(property)
  49. ? this._priorities.get(property)
  50. : "";
  51. this._setProperty(property, val, priority);
  52. }
  53. }
  54. },
  55. get() {
  56. return this.getPropertyValue(property);
  57. },
  58. enumerable: true,
  59. configurable: true
  60. };
  61. module.exports.property = property;