You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.3 KiB

4 years ago
  1. "use strict";
  2. function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
  3. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _defaults(subClass, superClass); }
  4. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  5. var list = require('postcss').list;
  6. var flexSpec = require('./flex-spec');
  7. var Declaration = require('../declaration');
  8. var Flex =
  9. /*#__PURE__*/
  10. function (_Declaration) {
  11. _inheritsLoose(Flex, _Declaration);
  12. function Flex() {
  13. return _Declaration.apply(this, arguments) || this;
  14. }
  15. var _proto = Flex.prototype;
  16. /**
  17. * Change property name for 2009 spec
  18. */
  19. _proto.prefixed = function prefixed(prop, prefix) {
  20. var spec;
  21. var _flexSpec = flexSpec(prefix);
  22. spec = _flexSpec[0];
  23. prefix = _flexSpec[1];
  24. if (spec === 2009) {
  25. return prefix + 'box-flex';
  26. }
  27. return _Declaration.prototype.prefixed.call(this, prop, prefix);
  28. }
  29. /**
  30. * Return property name by final spec
  31. */
  32. ;
  33. _proto.normalize = function normalize() {
  34. return 'flex';
  35. }
  36. /**
  37. * Spec 2009 supports only first argument
  38. * Spec 2012 disallows unitless basis
  39. */
  40. ;
  41. _proto.set = function set(decl, prefix) {
  42. var spec = flexSpec(prefix)[0];
  43. if (spec === 2009) {
  44. decl.value = list.space(decl.value)[0];
  45. decl.value = Flex.oldValues[decl.value] || decl.value;
  46. return _Declaration.prototype.set.call(this, decl, prefix);
  47. }
  48. if (spec === 2012) {
  49. var components = list.space(decl.value);
  50. if (components.length === 3 && components[2] === '0') {
  51. decl.value = components.slice(0, 2).concat('0px').join(' ');
  52. }
  53. }
  54. return _Declaration.prototype.set.call(this, decl, prefix);
  55. };
  56. return Flex;
  57. }(Declaration);
  58. _defineProperty(Flex, "names", ['flex', 'box-flex']);
  59. _defineProperty(Flex, "oldValues", {
  60. auto: '1',
  61. none: '0'
  62. });
  63. module.exports = Flex;