fontSize.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. const parsers = require("../parsers");
  3. const property = "font-size";
  4. const shorthand = "font";
  5. module.exports.parse = (v, opt = {}) => {
  6. const { globalObject } = opt;
  7. if (v === "") {
  8. return v;
  9. }
  10. const value = parsers.parsePropertyValue(property, v, {
  11. globalObject,
  12. inArray: true
  13. });
  14. if (Array.isArray(value) && value.length === 1) {
  15. return parsers.resolveNumericValue(value, {
  16. min: 0,
  17. type: "length"
  18. });
  19. } else if (typeof value === "string") {
  20. return value;
  21. }
  22. };
  23. module.exports.definition = {
  24. set(v) {
  25. v = parsers.prepareValue(v);
  26. if (parsers.hasVarFunc(v)) {
  27. this._setProperty(shorthand, "");
  28. this._setProperty(property, v);
  29. } else {
  30. const val = module.exports.parse(v, {
  31. globalObject: this._global
  32. });
  33. if (typeof val === "string") {
  34. const priority =
  35. !this._priorities.get(shorthand) && this._priorities.has(property)
  36. ? this._priorities.get(property)
  37. : "";
  38. this._setProperty(property, val, priority);
  39. }
  40. }
  41. },
  42. get() {
  43. return this.getPropertyValue(property);
  44. },
  45. enumerable: true,
  46. configurable: true
  47. };
  48. module.exports.property = property;