intrinsic.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 OldValue = require('../old-value');
  6. var Value = require('../value');
  7. function _regexp(name) {
  8. return new RegExp("(^|[\\s,(])(" + name + "($|[\\s),]))", 'gi');
  9. }
  10. var Intrinsic = /*#__PURE__*/function (_Value) {
  11. _inheritsLoose(Intrinsic, _Value);
  12. function Intrinsic() {
  13. return _Value.apply(this, arguments) || this;
  14. }
  15. var _proto = Intrinsic.prototype;
  16. _proto.regexp = function regexp() {
  17. if (!this.regexpCache) this.regexpCache = _regexp(this.name);
  18. return this.regexpCache;
  19. };
  20. _proto.isStretch = function isStretch() {
  21. return this.name === 'stretch' || this.name === 'fill' || this.name === 'fill-available';
  22. };
  23. _proto.replace = function replace(string, prefix) {
  24. if (prefix === '-moz-' && this.isStretch()) {
  25. return string.replace(this.regexp(), '$1-moz-available$3');
  26. }
  27. if (prefix === '-webkit-' && this.isStretch()) {
  28. return string.replace(this.regexp(), '$1-webkit-fill-available$3');
  29. }
  30. return _Value.prototype.replace.call(this, string, prefix);
  31. };
  32. _proto.old = function old(prefix) {
  33. var prefixed = prefix + this.name;
  34. if (this.isStretch()) {
  35. if (prefix === '-moz-') {
  36. prefixed = '-moz-available';
  37. } else if (prefix === '-webkit-') {
  38. prefixed = '-webkit-fill-available';
  39. }
  40. }
  41. return new OldValue(this.name, prefixed, prefixed, _regexp(prefixed));
  42. };
  43. _proto.add = function add(decl, prefix) {
  44. if (decl.prop.includes('grid') && prefix !== '-webkit-') {
  45. return undefined;
  46. }
  47. return _Value.prototype.add.call(this, decl, prefix);
  48. };
  49. return Intrinsic;
  50. }(Value);
  51. _defineProperty(Intrinsic, "names", ['max-content', 'min-content', 'fit-content', 'fill', 'fill-available', 'stretch']);
  52. module.exports = Intrinsic;