intrinsic.js 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  4. function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  5. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  6. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  7. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _defaults(subClass, superClass); }
  9. 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; }
  10. var OldValue = require('../old-value');
  11. var Value = require('../value');
  12. function _regexp(name) {
  13. return new RegExp("(^|[\\s,(])(" + name + "($|[\\s),]))", 'gi');
  14. }
  15. var Intrinsic = /*#__PURE__*/function (_Value) {
  16. _inheritsLoose(Intrinsic, _Value);
  17. var _super = _createSuper(Intrinsic);
  18. function Intrinsic() {
  19. return _Value.apply(this, arguments) || this;
  20. }
  21. var _proto = Intrinsic.prototype;
  22. _proto.regexp = function regexp() {
  23. if (!this.regexpCache) this.regexpCache = _regexp(this.name);
  24. return this.regexpCache;
  25. };
  26. _proto.isStretch = function isStretch() {
  27. return this.name === 'stretch' || this.name === 'fill' || this.name === 'fill-available';
  28. };
  29. _proto.replace = function replace(string, prefix) {
  30. if (prefix === '-moz-' && this.isStretch()) {
  31. return string.replace(this.regexp(), '$1-moz-available$3');
  32. }
  33. if (prefix === '-webkit-' && this.isStretch()) {
  34. return string.replace(this.regexp(), '$1-webkit-fill-available$3');
  35. }
  36. return _Value.prototype.replace.call(this, string, prefix);
  37. };
  38. _proto.old = function old(prefix) {
  39. var prefixed = prefix + this.name;
  40. if (this.isStretch()) {
  41. if (prefix === '-moz-') {
  42. prefixed = '-moz-available';
  43. } else if (prefix === '-webkit-') {
  44. prefixed = '-webkit-fill-available';
  45. }
  46. }
  47. return new OldValue(this.name, prefixed, prefixed, _regexp(prefixed));
  48. };
  49. _proto.add = function add(decl, prefix) {
  50. if (decl.prop.includes('grid') && prefix !== '-webkit-') {
  51. return undefined;
  52. }
  53. return _Value.prototype.add.call(this, decl, prefix);
  54. };
  55. return Intrinsic;
  56. }(Value);
  57. _defineProperty(Intrinsic, "names", ['max-content', 'min-content', 'fit-content', 'fill', 'fill-available', 'stretch']);
  58. module.exports = Intrinsic;