{"version":3,"file":"progress2.mjs","names":[],"sources":["../../../../../../packages/components/progress/src/progress.vue"],"sourcesContent":["<template>\n  <div\n    :class=\"[\n      ns.b(),\n      ns.m(type),\n      ns.is(status),\n      {\n        [ns.m('without-text')]: !showText,\n        [ns.m('text-inside')]: textInside,\n      },\n    ]\"\n    role=\"progressbar\"\n    :aria-valuenow=\"percentage\"\n    aria-valuemin=\"0\"\n    aria-valuemax=\"100\"\n  >\n    <div v-if=\"type === 'line'\" :class=\"ns.b('bar')\">\n      <div\n        :class=\"ns.be('bar', 'outer')\"\n        :style=\"{ height: `${strokeWidth}px` }\"\n      >\n        <div\n          :class=\"[\n            ns.be('bar', 'inner'),\n            { [ns.bem('bar', 'inner', 'indeterminate')]: indeterminate },\n            { [ns.bem('bar', 'inner', 'striped')]: striped },\n            { [ns.bem('bar', 'inner', 'striped-flow')]: stripedFlow },\n          ]\"\n          :style=\"barStyle\"\n        >\n          <div\n            v-if=\"(showText || $slots.default) && textInside\"\n            :class=\"ns.be('bar', 'innerText')\"\n          >\n            <slot :percentage=\"percentage\">\n              <span>{{ content }}</span>\n            </slot>\n          </div>\n        </div>\n      </div>\n    </div>\n    <div\n      v-else\n      :class=\"ns.b('circle')\"\n      :style=\"{ height: `${width}px`, width: `${width}px` }\"\n    >\n      <svg viewBox=\"0 0 100 100\">\n        <path\n          :class=\"ns.be('circle', 'track')\"\n          :d=\"trackPath\"\n          :stroke=\"`var(${ns.cssVarName('fill-color-light')}, #e5e9f2)`\"\n          :stroke-linecap=\"strokeLinecap\"\n          :stroke-width=\"relativeStrokeWidth\"\n          fill=\"none\"\n          :style=\"trailPathStyle\"\n        />\n        <path\n          :class=\"ns.be('circle', 'path')\"\n          :d=\"trackPath\"\n          :stroke=\"stroke\"\n          fill=\"none\"\n          :opacity=\"percentage ? 1 : 0\"\n          :stroke-linecap=\"strokeLinecap\"\n          :stroke-width=\"relativeStrokeWidth\"\n          :style=\"circlePathStyle\"\n        />\n      </svg>\n    </div>\n    <div\n      v-if=\"(showText || $slots.default) && !textInside\"\n      :class=\"ns.e('text')\"\n      :style=\"{ fontSize: `${progressTextSize}px` }\"\n    >\n      <slot :percentage=\"percentage\">\n        <span v-if=\"!status\">{{ content }}</span>\n        <el-icon v-else>\n          <component :is=\"statusIcon\" />\n        </el-icon>\n      </slot>\n    </div>\n  </div>\n</template>\n\n<script lang=\"ts\" setup>\nimport { computed } from 'vue'\nimport { ElIcon } from '@element-plus/components/icon'\nimport {\n  Check,\n  CircleCheck,\n  CircleClose,\n  Close,\n  WarningFilled,\n} from '@element-plus/icons-vue'\nimport { useNamespace } from '@element-plus/hooks'\nimport { isFunction, isString } from '@element-plus/utils'\n\nimport type { CSSProperties } from 'vue'\nimport type { ProgressColor, ProgressProps } from './progress'\n\ndefineOptions({\n  name: 'ElProgress',\n})\n\nconst STATUS_COLOR_MAP: Record<string, string> = {\n  success: '#13ce66',\n  exception: '#ff4949',\n  warning: '#e6a23c',\n  default: '#20a0ff',\n}\n\nconst props = withDefaults(defineProps<ProgressProps>(), {\n  type: 'line',\n  percentage: 0,\n  status: '',\n  duration: 3,\n  strokeWidth: 6,\n  strokeLinecap: 'round',\n  width: 126,\n  showText: true,\n  color: '',\n  format: (percentage: number): string => `${percentage}%`,\n})\n\nconst ns = useNamespace('progress')\n\nconst barStyle = computed<CSSProperties>(() => {\n  const barStyle: CSSProperties = {\n    width: `${props.percentage}%`,\n    animationDuration: `${props.duration}s`,\n  }\n  const color = getCurrentColor(props.percentage)\n  if (color.includes('gradient')) {\n    barStyle.background = color\n  } else {\n    barStyle.backgroundColor = color\n  }\n  return barStyle\n})\n\nconst relativeStrokeWidth = computed(() =>\n  ((props.strokeWidth / props.width) * 100).toFixed(1)\n)\n\nconst radius = computed(() => {\n  if (['circle', 'dashboard'].includes(props.type)) {\n    return Number.parseInt(\n      `${50 - Number.parseFloat(relativeStrokeWidth.value) / 2}`,\n      10\n    )\n  }\n  return 0\n})\n\nconst trackPath = computed(() => {\n  const r = radius.value\n  const isDashboard = props.type === 'dashboard'\n  return `\n          M 50 50\n          m 0 ${isDashboard ? '' : '-'}${r}\n          a ${r} ${r} 0 1 1 0 ${isDashboard ? '-' : ''}${r * 2}\n          a ${r} ${r} 0 1 1 0 ${isDashboard ? '' : '-'}${r * 2}\n          `\n})\n\nconst perimeter = computed(() => 2 * Math.PI * radius.value)\n\nconst rate = computed(() => (props.type === 'dashboard' ? 0.75 : 1))\n\nconst strokeDashoffset = computed(() => {\n  const offset = (-1 * perimeter.value * (1 - rate.value)) / 2\n  return `${offset}px`\n})\n\nconst trailPathStyle = computed<CSSProperties>(() => ({\n  strokeDasharray: `${perimeter.value * rate.value}px, ${perimeter.value}px`,\n  strokeDashoffset: strokeDashoffset.value,\n}))\n\nconst circlePathStyle = computed<CSSProperties>(() => ({\n  strokeDasharray: `${\n    perimeter.value * rate.value * (props.percentage / 100)\n  }px, ${perimeter.value}px`,\n  strokeDashoffset: strokeDashoffset.value,\n  transition:\n    'stroke-dasharray 0.6s ease 0s, stroke 0.6s ease, opacity ease 0.6s',\n}))\n\nconst stroke = computed(() => {\n  let ret: string\n  if (props.color) {\n    ret = getCurrentColor(props.percentage)\n  } else {\n    ret = STATUS_COLOR_MAP[props.status] || STATUS_COLOR_MAP.default\n  }\n  return ret\n})\n\nconst statusIcon = computed(() => {\n  if (props.status === 'warning') {\n    return WarningFilled\n  }\n  if (props.type === 'line') {\n    return props.status === 'success' ? CircleCheck : CircleClose\n  } else {\n    return props.status === 'success' ? Check : Close\n  }\n})\n\nconst progressTextSize = computed(() => {\n  return props.type === 'line'\n    ? 12 + props.strokeWidth * 0.4\n    : props.width * 0.111111 + 2\n})\n\nconst content = computed(() => props.format(props.percentage))\n\nfunction getColors(color: ProgressColor[]) {\n  const span = 100 / color.length\n  const seriesColors = color.map((seriesColor, index) => {\n    if (isString(seriesColor)) {\n      return {\n        color: seriesColor,\n        percentage: (index + 1) * span,\n      }\n    }\n    return seriesColor\n  })\n  return seriesColors.sort((a, b) => a.percentage - b.percentage)\n}\n\nconst getCurrentColor = (percentage: number) => {\n  const { color } = props\n  if (isFunction(color)) {\n    return color(percentage)\n  } else if (isString(color)) {\n    return color\n  } else {\n    const colors = getColors(color)\n    for (const color of colors) {\n      if (color.percentage > percentage) return color.color\n    }\n    return colors[colors.length - 1]?.color\n  }\n}\n</script>\n"],"mappings":""}