44387386f002bd6253ce76a116b1f3f92d2aa6ea2a72db0200452464fbba8a8f60596461750c6e15150ddf03b4fe81230794542df72502546aed1653458352 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import { defineComponent, computed, unref, openBlock, createElementBlock, normalizeClass, withModifiers, createBlock, Transition, withCtx, withDirectives, createElementVNode, createVNode, vShow, createCommentVNode, normalizeStyle, renderSlot, Fragment, renderList, toDisplayString } from 'vue';
  2. import { ElIcon } from '../../icon/index.mjs';
  3. import { ArrowLeft, ArrowRight } from '@element-plus/icons-vue';
  4. import { carouselProps, carouselEmits } from './carousel.mjs';
  5. import { useCarousel } from './use-carousel.mjs';
  6. import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
  7. import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
  8. import { useLocale } from '../../../hooks/use-locale/index.mjs';
  9. const COMPONENT_NAME = "ElCarousel";
  10. const __default__ = defineComponent({
  11. name: COMPONENT_NAME
  12. });
  13. const _sfc_main = /* @__PURE__ */ defineComponent({
  14. ...__default__,
  15. props: carouselProps,
  16. emits: carouselEmits,
  17. setup(__props, { expose, emit }) {
  18. const props = __props;
  19. const {
  20. root,
  21. activeIndex,
  22. exposeActiveIndex,
  23. arrowDisplay,
  24. hasLabel,
  25. hover,
  26. isCardType,
  27. items,
  28. isVertical,
  29. containerStyle,
  30. handleButtonEnter,
  31. handleButtonLeave,
  32. handleIndicatorClick,
  33. handleMouseEnter,
  34. handleMouseLeave,
  35. setActiveItem,
  36. prev,
  37. next,
  38. PlaceholderItem,
  39. isTwoLengthShow,
  40. ItemsSorter,
  41. throttledArrowClick,
  42. throttledIndicatorHover
  43. } = useCarousel(props, emit);
  44. const ns = useNamespace("carousel");
  45. const { t } = useLocale();
  46. const carouselClasses = computed(() => {
  47. const classes = [ns.b(), ns.m(props.direction)];
  48. if (unref(isCardType)) {
  49. classes.push(ns.m("card"));
  50. }
  51. return classes;
  52. });
  53. const indicatorsClasses = computed(() => {
  54. const classes = [ns.e("indicators"), ns.em("indicators", props.direction)];
  55. if (unref(hasLabel)) {
  56. classes.push(ns.em("indicators", "labels"));
  57. }
  58. if (props.indicatorPosition === "outside") {
  59. classes.push(ns.em("indicators", "outside"));
  60. }
  61. if (unref(isVertical)) {
  62. classes.push(ns.em("indicators", "right"));
  63. }
  64. return classes;
  65. });
  66. function handleTransitionStart(e) {
  67. if (!props.motionBlur)
  68. return;
  69. const kls = unref(isVertical) ? `${ns.namespace.value}-transitioning-vertical` : `${ns.namespace.value}-transitioning`;
  70. e.currentTarget.classList.add(kls);
  71. }
  72. function handleTransitionEnd(e) {
  73. if (!props.motionBlur)
  74. return;
  75. const kls = unref(isVertical) ? `${ns.namespace.value}-transitioning-vertical` : `${ns.namespace.value}-transitioning`;
  76. e.currentTarget.classList.remove(kls);
  77. }
  78. expose({
  79. activeIndex: exposeActiveIndex,
  80. setActiveItem,
  81. prev,
  82. next
  83. });
  84. return (_ctx, _cache) => {
  85. return openBlock(), createElementBlock("div", {
  86. ref_key: "root",
  87. ref: root,
  88. class: normalizeClass(unref(carouselClasses)),
  89. onMouseenter: withModifiers(unref(handleMouseEnter), ["stop"]),
  90. onMouseleave: withModifiers(unref(handleMouseLeave), ["stop"])
  91. }, [
  92. unref(arrowDisplay) ? (openBlock(), createBlock(Transition, {
  93. key: 0,
  94. name: "carousel-arrow-left",
  95. persisted: ""
  96. }, {
  97. default: withCtx(() => [
  98. withDirectives(createElementVNode("button", {
  99. type: "button",
  100. class: normalizeClass([unref(ns).e("arrow"), unref(ns).em("arrow", "left")]),
  101. "aria-label": unref(t)("el.carousel.leftArrow"),
  102. onMouseenter: ($event) => unref(handleButtonEnter)("left"),
  103. onMouseleave: unref(handleButtonLeave),
  104. onClick: withModifiers(($event) => unref(throttledArrowClick)(unref(activeIndex) - 1), ["stop"])
  105. }, [
  106. createVNode(unref(ElIcon), null, {
  107. default: withCtx(() => [
  108. createVNode(unref(ArrowLeft))
  109. ]),
  110. _: 1
  111. })
  112. ], 42, ["aria-label", "onMouseenter", "onMouseleave", "onClick"]), [
  113. [
  114. vShow,
  115. (_ctx.arrow === "always" || unref(hover)) && (props.loop || unref(activeIndex) > 0)
  116. ]
  117. ])
  118. ]),
  119. _: 1
  120. })) : createCommentVNode("v-if", true),
  121. unref(arrowDisplay) ? (openBlock(), createBlock(Transition, {
  122. key: 1,
  123. name: "carousel-arrow-right",
  124. persisted: ""
  125. }, {
  126. default: withCtx(() => [
  127. withDirectives(createElementVNode("button", {
  128. type: "button",
  129. class: normalizeClass([unref(ns).e("arrow"), unref(ns).em("arrow", "right")]),
  130. "aria-label": unref(t)("el.carousel.rightArrow"),
  131. onMouseenter: ($event) => unref(handleButtonEnter)("right"),
  132. onMouseleave: unref(handleButtonLeave),
  133. onClick: withModifiers(($event) => unref(throttledArrowClick)(unref(activeIndex) + 1), ["stop"])
  134. }, [
  135. createVNode(unref(ElIcon), null, {
  136. default: withCtx(() => [
  137. createVNode(unref(ArrowRight))
  138. ]),
  139. _: 1
  140. })
  141. ], 42, ["aria-label", "onMouseenter", "onMouseleave", "onClick"]), [
  142. [
  143. vShow,
  144. (_ctx.arrow === "always" || unref(hover)) && (props.loop || unref(activeIndex) < unref(items).length - 1)
  145. ]
  146. ])
  147. ]),
  148. _: 1
  149. })) : createCommentVNode("v-if", true),
  150. createElementVNode("div", {
  151. class: normalizeClass(unref(ns).e("container")),
  152. style: normalizeStyle(unref(containerStyle)),
  153. onTransitionstart: handleTransitionStart,
  154. onTransitionend: handleTransitionEnd
  155. }, [
  156. createVNode(unref(PlaceholderItem)),
  157. renderSlot(_ctx.$slots, "default")
  158. ], 38),
  159. createVNode(unref(ItemsSorter), null, {
  160. default: withCtx(() => [
  161. _ctx.indicatorPosition !== "none" ? (openBlock(), createElementBlock("ul", {
  162. key: 0,
  163. class: normalizeClass(unref(indicatorsClasses))
  164. }, [
  165. (openBlock(true), createElementBlock(Fragment, null, renderList(unref(items), (item, index) => {
  166. return withDirectives((openBlock(), createElementBlock("li", {
  167. key: index,
  168. class: normalizeClass([
  169. unref(ns).e("indicator"),
  170. unref(ns).em("indicator", _ctx.direction),
  171. unref(ns).is("active", index === unref(activeIndex))
  172. ]),
  173. onMouseenter: ($event) => unref(throttledIndicatorHover)(index),
  174. onClick: withModifiers(($event) => unref(handleIndicatorClick)(index), ["stop"])
  175. }, [
  176. createElementVNode("button", {
  177. class: normalizeClass(unref(ns).e("button")),
  178. "aria-label": unref(t)("el.carousel.indicator", { index: index + 1 })
  179. }, [
  180. unref(hasLabel) ? (openBlock(), createElementBlock("span", { key: 0 }, toDisplayString(item.props.label), 1)) : createCommentVNode("v-if", true)
  181. ], 10, ["aria-label"])
  182. ], 42, ["onMouseenter", "onClick"])), [
  183. [vShow, unref(isTwoLengthShow)(index)]
  184. ]);
  185. }), 128))
  186. ], 2)) : createCommentVNode("v-if", true)
  187. ]),
  188. _: 1
  189. }),
  190. props.motionBlur ? (openBlock(), createElementBlock("svg", {
  191. key: 2,
  192. xmlns: "http://www.w3.org/2000/svg",
  193. version: "1.1",
  194. style: { "display": "none" }
  195. }, [
  196. createElementVNode("defs", null, [
  197. createElementVNode("filter", { id: "elCarouselHorizontal" }, [
  198. createElementVNode("feGaussianBlur", {
  199. in: "SourceGraphic",
  200. stdDeviation: "12,0"
  201. })
  202. ]),
  203. createElementVNode("filter", { id: "elCarouselVertical" }, [
  204. createElementVNode("feGaussianBlur", {
  205. in: "SourceGraphic",
  206. stdDeviation: "0,10"
  207. })
  208. ])
  209. ])
  210. ])) : createCommentVNode("v-if", true)
  211. ], 42, ["onMouseenter", "onMouseleave"]);
  212. };
  213. }
  214. });
  215. var Carousel = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "carousel.vue"]]);
  216. export { Carousel as default };
  217. //# sourceMappingURL=carousel2.mjs.map