{"version":3,"file":"message2.mjs","sources":["../../../../../../packages/components/message/src/message.vue"],"sourcesContent":["<template>\r\n  <transition\r\n    name=\"sg-message-fade\"\r\n    @before-leave=\"onClose\"\r\n    @after-leave=\"$emit('destroy')\"\r\n  >\r\n    <div\r\n      v-show=\"visible\"\r\n      :id=\"id\"\r\n      :class=\"[\r\n        ns.b(),\r\n        { [ns.m(type)]: type && !icon },\r\n        ns.is('center', center),\r\n        ns.is('closable', closable),\r\n        ns.is('description', isDescription),\r\n        customClass,\r\n      ]\"\r\n      :style=\"customStyle\"\r\n      role=\"alert\"\r\n      @mouseenter=\"clearTimer\"\r\n      @mouseleave=\"startTimer\"\r\n    >\r\n      <sg-badge\r\n        v-if=\"repeatNum > 1\"\r\n        :value=\"repeatNum\"\r\n        :type=\"badgeType\"\r\n        :class=\"ns.e('badge')\"\r\n      />\r\n      <sg-icon v-if=\"iconComponent\" :class=\"ns.e('icon')\">\r\n        <component :is=\"iconComponent\" />\r\n      </sg-icon>\r\n      <slot>\r\n        <div :class=\"ns.e('content')\">\r\n          <div :class=\"ns.em('content', 'title')\">{{ content }}</div>\r\n          <div v-if=\"isDescription\" :class=\"ns.em('content', 'description')\">{{ description }}</div>\r\n        </div>\r\n      </slot>\r\n      <sg-icon v-if=\"closable\" :class=\"ns.e('closebtn')\" @click.stop=\"close\">\r\n        <Close />\r\n      </sg-icon>\r\n    </div>\r\n  </transition>\r\n</template>\r\n\r\n<script lang=\"ts\">\r\nimport { defineComponent, computed, ref, onMounted, watch } from 'vue'\r\nimport { useEventListener, useTimeoutFn } from '@vueuse/core'\r\nimport { useGlobalComponentSettings } from '@sgui-plus/hooks'\r\nimport { EVENT_CODE } from '@sgui-plus/utils/aria'\r\nimport SgBadge from '@sgui-plus/components/badge'\r\nimport { SgIcon } from '@sgui-plus/components/icon'\r\nimport { TypeComponents, TypeComponentsMap } from '@sgui-plus/utils/icon'\r\n\r\nimport { messageEmits, messageProps } from './message'\r\nimport type { BadgeProps } from '@sgui-plus/components/badge'\r\n\r\nimport type { CSSProperties } from 'vue'\r\n\r\nexport default defineComponent({\r\n  name: 'SgMessage',\r\n\r\n  components: {\r\n    SgBadge,\r\n    SgIcon,\r\n    ...TypeComponents,\r\n  },\r\n\r\n  props: messageProps,\r\n  emits: messageEmits,\r\n\r\n  setup(props) {\r\n    const { ns, zIndex } = useGlobalComponentSettings('message')\r\n    const { currentZIndex, nextZIndex } = zIndex\r\n\r\n    const visible = ref(false)\r\n\r\n    const badgeType = ref<BadgeProps['type']>(\r\n      props.type ? (props.type === 'error' ? 'danger' : props.type) : 'info'\r\n    )\r\n\r\n    let stopTimer: (() => void) | undefined = undefined\r\n\r\n    const iconComponent = computed(() => {\r\n      return props.icon || TypeComponentsMap[props.type] || ''\r\n    })\r\n\r\n    const isDescription = computed(() => !!props.description)\r\n\r\n    const customStyle = computed<CSSProperties>(() => ({\r\n      top: `${props.top}px`,\r\n      zIndex: currentZIndex.value,\r\n    }))\r\n\r\n    function startTimer() {\r\n      if (props.duration > 0) {\r\n        ;({ stop: stopTimer } = useTimeoutFn(() => {\r\n          if (visible.value) close()\r\n        }, props.duration))\r\n      }\r\n    }\r\n\r\n    function clearTimer() {\r\n      stopTimer?.()\r\n    }\r\n\r\n    function close() {\r\n      visible.value = false\r\n    }\r\n\r\n    function keydown({ code }: KeyboardEvent) {\r\n      if (code === EVENT_CODE.esc) {\r\n        // press esc to close the message\r\n        if (visible.value) {\r\n          close()\r\n        }\r\n      } else {\r\n        startTimer() // resume timer\r\n      }\r\n    }\r\n\r\n    onMounted(() => {\r\n      startTimer()\r\n      nextZIndex()\r\n      visible.value = true\r\n    })\r\n\r\n    watch(\r\n      () => props.repeatNum,\r\n      () => {\r\n        clearTimer()\r\n        startTimer()\r\n      }\r\n    )\r\n\r\n    useEventListener(document, 'keydown', keydown)\r\n\r\n    return {\r\n      ns,\r\n\r\n      iconComponent,\r\n      isDescription,\r\n      customStyle,\r\n      visible,\r\n      badgeType,\r\n\r\n      close,\r\n      clearTimer,\r\n      startTimer,\r\n    }\r\n  },\r\n})\r\n</script>\r\n"],"names":["_resolveComponent","_openBlock","_createBlock","_Transition","_withCtx","_withDirectives","_createElementVNode","_normalizeClass","_normalizeStyle","_createCommentVNode","_renderSlot","_toDisplayString","_createElementBlock","_withModifiers"],"mappings":";;;;;;;;2BACEA,gBAwCa,CAAA,OAAA,CAAA,CAAA;AAtCV,EAAA,OAAAC,SAAA,EAAqB,EAAAC,WAAA,CAAAC,UAAA,EAAA;AAAA,IACrB,IAAA,EAAA,iBAAA;AAAA,IAHH,aAwCa,EAAA,IAAA,CAAA,OAAA;AAAA,IAAA,YAAA,EAAA,MAAA,CAAA,CAAA,CAAA,KAAA,MAAA,CAAA,CAAA,CAAA,GAAA,CAAA,MAAA,KAAA,IAAA,CAAA,KAAA,CAAA,SAAA,CAAA,CAAA;;;aAjCJC,OAAE,CAAA,MAAA;AAAA,MACDC,cAAA,CAAAC,kBAAA,CAAA,KAAA,EAAA;AAAA,QAAa,EAAI,EAAA,IAAA,CAAA,EAAA;AAAA,QAAA,KAAA,EAAgBC,cAAS,CAAA;AAAA,UAA8B,QAAG,CAAE,EAAA;AAAA,UAA6B,EAAA,CAAA,IAAA,CAAG,EAAE,CAAA,CAAA,CAAA,IAAA,CAAA,IAAA,CAAA,GAAa,IAAQ,CAAA,IAAA,IAAA,CAAA,IAAA,CAAA,IAAA,EAAA;AAAA,UAAY,IAAA,CAAA,EAAA,CAAG,GAAE,QAAgB,EAAA,IAAA,CAAA,MAAA,CAAA;AAAA,UAAyB,IAAW,CAAA,EAAA,CAAA,EAAA,CAAA,UAAA,EAAA,IAAA,CAAA,QAAA,CAAA;AAAA,UAAA,IAAA,CAAA,EAAA,CAAA,EAAA,CAAA,aAAA,EAAA,IAAA,CAAA,aAAA,CAAA;UAQ9M,IAAK,CAAA,WAAA;AAAA,SAAA,CAAA;QAEL,KAAU,EAAAC,cAAA,CAAA,IAAA,CAAA,WAAA,CAAA;AAAA,QACV,IAAA,EAAA,OAA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