flex.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 flexSpec = require('./flex-spec');
  6. var Declaration = require('../declaration');
  7. var list = require('postcss').list;
  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. _proto.prefixed = function prefixed(prop, prefix) {
  17. var spec;
  18. var _flexSpec = flexSpec(prefix);
  19. spec = _flexSpec[0];
  20. prefix = _flexSpec[1];
  21. if (spec === 2009) {
  22. return prefix + 'box-flex';
  23. }
  24. return _Declaration.prototype.prefixed.call(this, prop, prefix);
  25. }
  26. /**
  27. * Return property name by final spec
  28. */
  29. ;
  30. _proto.normalize = function normalize() {
  31. return 'flex';
  32. }
  33. /**
  34. * Spec 2009 supports only first argument
  35. * Spec 2012 disallows unitless basis
  36. */
  37. ;
  38. _proto.set = function set(decl, prefix) {
  39. var spec = flexSpec(prefix)[0];
  40. if (spec === 2009) {
  41. decl.value = list.space(decl.value)[0];
  42. decl.value = Flex.oldValues[decl.value] || decl.value;
  43. return _Declaration.prototype.set.call(this, decl, prefix);
  44. }
  45. if (spec === 2012) {
  46. var components = list.space(decl.value);
  47. if (components.length === 3 && components[2] === '0') {
  48. decl.value = components.slice(0, 2).concat('0px').join(' ');
  49. }
  50. }
  51. return _Declaration.prototype.set.call(this, decl, prefix);
  52. };
  53. return Flex;
  54. }(Declaration);
  55. _defineProperty(Flex, "names", ['flex', 'box-flex']);
  56. _defineProperty(Flex, "oldValues", {
  57. auto: '1',
  58. none: '0'
  59. /**
  60. * Change property name for 2009 spec
  61. */
  62. });
  63. module.exports = Flex;