utils.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var core = require('@vueuse/core');
  4. const buildPopperOptions = (props, arrowProps) => {
  5. const { placement, strategy, popperOptions } = props;
  6. const options = {
  7. placement,
  8. strategy,
  9. ...popperOptions,
  10. modifiers: genModifiers(props)
  11. };
  12. attachArrow(options, arrowProps);
  13. deriveExtraModifiers(options, popperOptions == null ? void 0 : popperOptions.modifiers);
  14. return options;
  15. };
  16. const unwrapMeasurableEl = ($el) => {
  17. if (!core.isClient)
  18. return;
  19. return core.unrefElement($el);
  20. };
  21. function genModifiers(options) {
  22. const { offset, gpuAcceleration, fallbackPlacements } = options;
  23. return [
  24. {
  25. name: "offset",
  26. options: {
  27. offset: [0, offset != null ? offset : 12]
  28. }
  29. },
  30. {
  31. name: "preventOverflow",
  32. options: {
  33. padding: {
  34. top: 2,
  35. bottom: 2,
  36. left: 5,
  37. right: 5
  38. }
  39. }
  40. },
  41. {
  42. name: "flip",
  43. options: {
  44. padding: 5,
  45. fallbackPlacements
  46. }
  47. },
  48. {
  49. name: "computeStyles",
  50. options: {
  51. gpuAcceleration
  52. }
  53. }
  54. ];
  55. }
  56. function attachArrow(options, { arrowEl, arrowOffset }) {
  57. options.modifiers.push({
  58. name: "arrow",
  59. options: {
  60. element: arrowEl,
  61. padding: arrowOffset != null ? arrowOffset : 5
  62. }
  63. });
  64. }
  65. function deriveExtraModifiers(options, modifiers) {
  66. if (modifiers) {
  67. options.modifiers = [...options.modifiers, ...modifiers != null ? modifiers : []];
  68. }
  69. }
  70. exports.buildPopperOptions = buildPopperOptions;
  71. exports.unwrapMeasurableEl = unwrapMeasurableEl;
  72. //# sourceMappingURL=utils.js.map