top.js 1.0 KB

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