fontSize.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. var TYPES = require('../parsers').TYPES;
  3. var valueType = require('../parsers').valueType;
  4. var parseMeasurement = require('../parsers').parseMeasurement;
  5. var absoluteSizes = ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'];
  6. var relativeSizes = ['larger', 'smaller'];
  7. module.exports.isValid = function(v) {
  8. var type = valueType(v.toLowerCase());
  9. return (
  10. type === TYPES.LENGTH ||
  11. type === TYPES.PERCENT ||
  12. (type === TYPES.KEYWORD && absoluteSizes.indexOf(v.toLowerCase()) !== -1) ||
  13. (type === TYPES.KEYWORD && relativeSizes.indexOf(v.toLowerCase()) !== -1)
  14. );
  15. };
  16. function parse(v) {
  17. const valueAsString = String(v).toLowerCase();
  18. const optionalArguments = absoluteSizes.concat(relativeSizes);
  19. const isOptionalArgument = optionalArguments.some(
  20. stringValue => stringValue.toLowerCase() === valueAsString
  21. );
  22. return isOptionalArgument ? valueAsString : parseMeasurement(v);
  23. }
  24. module.exports.definition = {
  25. set: function(v) {
  26. this._setProperty('font-size', parse(v));
  27. },
  28. get: function() {
  29. return this.getPropertyValue('font-size');
  30. },
  31. enumerable: true,
  32. configurable: true,
  33. };