fontWeight.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "use strict";
  2. const parsers = require("../parsers");
  3. const property = "font-weight";
  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. const parsedValue = parsers.resolveNumericValue(value, {
  16. min: 1,
  17. max: 1000
  18. });
  19. if (!parsedValue) {
  20. return;
  21. }
  22. return parsedValue;
  23. } else if (typeof value === "string") {
  24. return value;
  25. }
  26. };
  27. module.exports.definition = {
  28. set(v) {
  29. v = parsers.prepareValue(v);
  30. if (parsers.hasVarFunc(v)) {
  31. this._setProperty(shorthand, "");
  32. this._setProperty(property, v);
  33. } else {
  34. const val = module.exports.parse(v, {
  35. globalObject: this._global
  36. });
  37. if (typeof val === "string") {
  38. const priority =
  39. !this._priorities.get(shorthand) && this._priorities.has(property)
  40. ? this._priorities.get(property)
  41. : "";
  42. this._setProperty(property, val, priority);
  43. }
  44. }
  45. },
  46. get() {
  47. return this.getPropertyValue(property);
  48. },
  49. enumerable: true,
  50. configurable: true
  51. };
  52. module.exports.property = property;