5c0a9630549359ee240851efecb00d7a232611bd420cb4675b006af5036eb184f20f1c1825c0f790f9e6f746348691d4368c0c7806a745b97b930e91611961 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var index$1 = require('../../icon/index.js');
  5. var avatar = require('./avatar.js');
  6. var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
  7. var index = require('../../../hooks/use-namespace/index.js');
  8. var shared = require('@vue/shared');
  9. var types = require('../../../utils/types.js');
  10. var style = require('../../../utils/dom/style.js');
  11. const __default__ = vue.defineComponent({
  12. name: "ElAvatar"
  13. });
  14. const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  15. ...__default__,
  16. props: avatar.avatarProps,
  17. emits: avatar.avatarEmits,
  18. setup(__props, { emit }) {
  19. const props = __props;
  20. const ns = index.useNamespace("avatar");
  21. const hasLoadError = vue.ref(false);
  22. const avatarClass = vue.computed(() => {
  23. const { size, icon, shape } = props;
  24. const classList = [ns.b()];
  25. if (shared.isString(size))
  26. classList.push(ns.m(size));
  27. if (icon)
  28. classList.push(ns.m("icon"));
  29. if (shape)
  30. classList.push(ns.m(shape));
  31. return classList;
  32. });
  33. const sizeStyle = vue.computed(() => {
  34. const { size } = props;
  35. return types.isNumber(size) ? ns.cssVarBlock({
  36. size: style.addUnit(size) || ""
  37. }) : void 0;
  38. });
  39. const fitStyle = vue.computed(() => ({
  40. objectFit: props.fit
  41. }));
  42. vue.watch(() => props.src, () => hasLoadError.value = false);
  43. function handleError(e) {
  44. hasLoadError.value = true;
  45. emit("error", e);
  46. }
  47. return (_ctx, _cache) => {
  48. return vue.openBlock(), vue.createElementBlock("span", {
  49. class: vue.normalizeClass(vue.unref(avatarClass)),
  50. style: vue.normalizeStyle(vue.unref(sizeStyle))
  51. }, [
  52. (_ctx.src || _ctx.srcSet) && !hasLoadError.value ? (vue.openBlock(), vue.createElementBlock("img", {
  53. key: 0,
  54. src: _ctx.src,
  55. alt: _ctx.alt,
  56. srcset: _ctx.srcSet,
  57. style: vue.normalizeStyle(vue.unref(fitStyle)),
  58. onError: handleError
  59. }, null, 44, ["src", "alt", "srcset"])) : _ctx.icon ? (vue.openBlock(), vue.createBlock(vue.unref(index$1.ElIcon), { key: 1 }, {
  60. default: vue.withCtx(() => [
  61. (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.icon)))
  62. ]),
  63. _: 1
  64. })) : vue.renderSlot(_ctx.$slots, "default", { key: 2 })
  65. ], 6);
  66. };
  67. }
  68. });
  69. var Avatar = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["__file", "avatar.vue"]]);
  70. exports["default"] = Avatar;
  71. //# sourceMappingURL=avatar2.js.map