VLazy.mjs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { withDirectives as _withDirectives, resolveDirective as _resolveDirective, createVNode as _createVNode } from "vue";
  2. // Composables
  3. import { makeComponentProps } from "../../composables/component.mjs";
  4. import { makeDimensionProps, useDimension } from "../../composables/dimensions.mjs";
  5. import { useProxiedModel } from "../../composables/proxiedModel.mjs";
  6. import { makeTagProps } from "../../composables/tag.mjs";
  7. import { makeTransitionProps, MaybeTransition } from "../../composables/transition.mjs"; // Directives
  8. import intersect from "../../directives/intersect/index.mjs"; // Utilities
  9. import { genericComponent, propsFactory, useRender } from "../../util/index.mjs"; // Types
  10. export const makeVLazyProps = propsFactory({
  11. modelValue: Boolean,
  12. options: {
  13. type: Object,
  14. // For more information on types, navigate to:
  15. // https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API
  16. default: () => ({
  17. root: undefined,
  18. rootMargin: undefined,
  19. threshold: undefined
  20. })
  21. },
  22. ...makeComponentProps(),
  23. ...makeDimensionProps(),
  24. ...makeTagProps(),
  25. ...makeTransitionProps({
  26. transition: 'fade-transition'
  27. })
  28. }, 'VLazy');
  29. export const VLazy = genericComponent()({
  30. name: 'VLazy',
  31. directives: {
  32. intersect
  33. },
  34. props: makeVLazyProps(),
  35. emits: {
  36. 'update:modelValue': value => true
  37. },
  38. setup(props, _ref) {
  39. let {
  40. slots
  41. } = _ref;
  42. const {
  43. dimensionStyles
  44. } = useDimension(props);
  45. const isActive = useProxiedModel(props, 'modelValue');
  46. function onIntersect(isIntersecting) {
  47. if (isActive.value) return;
  48. isActive.value = isIntersecting;
  49. }
  50. useRender(() => _withDirectives(_createVNode(props.tag, {
  51. "class": ['v-lazy', props.class],
  52. "style": [dimensionStyles.value, props.style]
  53. }, {
  54. default: () => [isActive.value && _createVNode(MaybeTransition, {
  55. "transition": props.transition,
  56. "appear": true
  57. }, {
  58. default: () => [slots.default?.()]
  59. })]
  60. }), [[_resolveDirective("intersect"), {
  61. handler: onIntersect,
  62. options: props.options
  63. }, null]]));
  64. return {};
  65. }
  66. });
  67. //# sourceMappingURL=VLazy.mjs.map