1+ <script lang =" ts" >
2+ import { tweened } from ' svelte/motion' ;
3+ import { cubicOut } from ' svelte/easing' ;
4+ import Fa from ' svelte-fa'
5+ export let height: number = 50 ;
6+ export let icon: any = null ;
7+ export let iconColor: string = " red" ;
8+ export let iconContrast: number = 100 ;
9+ export let iconDropShadowAmount: number = 0 ;
10+ export let iconScaling: number = 0.45 ;
11+ export let iconTranslateX: number = 0 ;
12+ export let iconTranslateY: number = 0 ;
13+ export let name: string = " " ;
14+ export let outlineColor: string = " red" ;
15+ export let outlineContrast: number = 100 ;
16+ export let outlineDropShadowAmount: number = 0 ;
17+ export let progressColor: string = " red" ;
18+ export let progressContrast: number = 100 ;
19+ export let progressDropShadowAmount: number = 0 ;
20+ export let progressValue: number = 100 ;
21+ export let rotateDegree: number = 0 ;
22+ export let translateX: number = 0 ;
23+ export let translateY: number = 0 ;
24+ export let width: number = 50 ;
25+ export let borderSize: number = 3 ;
26+
27+ let radius: number = 25 ;
28+ let stroke: number = 25 ;
29+ let minimumAxis: number = height ;
30+ let normalizedRadius: number = radius - (stroke / 2 );
31+ let circumference = normalizedRadius * 2 * Math .PI ;
32+ let strokeDashoffset: number = 0 ;
33+
34+ const progressTween = tweened (progressValue , {
35+ duration: 600 ,
36+ easing: cubicOut
37+ });
38+ $ : {
39+ progressTween .set (progressValue )
40+ }
41+ $ : {
42+ minimumAxis = height > width ? height : width ;
43+ radius = minimumAxis / 2 ;
44+ stroke = radius ;
45+ normalizedRadius = radius - (stroke / 2 );
46+ circumference = normalizedRadius * 2 * Math .PI ;
47+ }
48+ $ : {
49+ strokeDashoffset = minimumAxis - $progressTween / 100 * minimumAxis ;
50+ }
51+ </script >
52+
53+ <svg
54+ width ={radius * 2 }
55+ height ={radius * 2 }
56+ viewBox = " 0 0 {radius * 2} {radius * 2}"
57+ overflow =" visible"
58+ >
59+ <defs >
60+ <clipPath id ={name + " -cut-out-circle" }>
61+ <circle
62+ stroke-width ={stroke }
63+ r ={radius }
64+ cx ={radius }
65+ cy ={radius }
66+ />
67+ </clipPath >
68+ </defs >
69+ <g
70+ transform ="
71+ { rotateDegree > 0 ? " rotate (" +rotateDegree+" " +radius+" " +radius+" )" : " " }
72+ { " translate (" +translateX+" " +translateY+" )" }"
73+ >
74+ <circle
75+ stroke ={" black" }
76+ fill =" transparent"
77+ stroke-width ={borderSize }
78+ r ={normalizedRadius * 2 + (borderSize / 2 )}
79+ cx ={radius }
80+ cy ={radius }
81+ shape-rendering =" geometricPrecision"
82+ />
83+ <line
84+ x 1=" 50%"
85+ y 1=" 100%"
86+ x 2=" 50%"
87+ y 2=" 0%"
88+ stroke ={progressColor }
89+ stroke-dasharray ={minimumAxis }
90+ stroke-dashoffset ={strokeDashoffset }
91+ stroke-width ={minimumAxis }
92+ clip-path ="url(# {name + " -cut-out-circle" })"
93+ shape-rendering =" geometricPrecision"
94+ style ="filter: {progressDropShadowAmount ? " drop-shadow(0px 0px " + progressDropShadowAmount + " px " + progressColor + " )" : " " }
95+ {" contrast(" + progressContrast + " %)" };"
96+ />
97+ </g >
98+ <g style ="filter: {iconDropShadowAmount ? " drop-shadow(0px 0px " + iconDropShadowAmount + " px " + iconColor + " )" : " " }
99+ {" contrast(" + iconContrast + " %)" };" >
100+ <Fa icon ={icon } scale ={iconScaling } translateX ={iconTranslateX }
101+ translateY ={iconTranslateY } style ="color: {iconColor }" />
102+ </g >
103+ </svg >
0 commit comments