useStretchStyle.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _vue = require("vue");
  7. var _default = stretch => {
  8. const targetSize = (0, _vue.shallowRef)({
  9. width: 0,
  10. height: 0
  11. });
  12. function measureStretch(element) {
  13. targetSize.value = {
  14. width: element.offsetWidth,
  15. height: element.offsetHeight
  16. };
  17. }
  18. // Merge stretch style
  19. const style = (0, _vue.computed)(() => {
  20. const sizeStyle = {};
  21. if (stretch.value) {
  22. const {
  23. width,
  24. height
  25. } = targetSize.value;
  26. // Stretch with target
  27. if (stretch.value.indexOf('height') !== -1 && height) {
  28. sizeStyle.height = `${height}px`;
  29. } else if (stretch.value.indexOf('minHeight') !== -1 && height) {
  30. sizeStyle.minHeight = `${height}px`;
  31. }
  32. if (stretch.value.indexOf('width') !== -1 && width) {
  33. sizeStyle.width = `${width}px`;
  34. } else if (stretch.value.indexOf('minWidth') !== -1 && width) {
  35. sizeStyle.minWidth = `${width}px`;
  36. }
  37. }
  38. return sizeStyle;
  39. });
  40. return [style, measureStretch];
  41. };
  42. exports.default = _default;