<commit_before>﻿using System;
using System.Threading.Tasks;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media.Animation;

namespace AppStudio.Uwp
{
    public static class AnimationExtensions
    {
        public static Storyboard AnimateX(this FrameworkElement element, double x, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.GetTranslateX() != x)
            {
                return AnimateDouble(element, "TranslateX", element.Width, x, duration, easingFunction);
            }
            return null;
        }
        public static async Task AnimateXAsync(this FrameworkElement element, double x, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.GetTranslateX() != x)
            {
                await AnimateDoubleAsync(element, "TranslateX", element.Width, x, duration, easingFunction);
            }
        }

        public static Storyboard AnimateY(this FrameworkElement element, double y, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.GetTranslateY() != y)
            {
                return AnimateDouble(element, "TranslateY", element.Width, y, duration, easingFunction);
            }
            return null;
        }
        public static async Task AnimateYAsync(this FrameworkElement element, double y, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.GetTranslateY() != y)
            {
                await AnimateDoubleAsync(element, "TranslateY", element.Width, y, duration, easingFunction);
            }
        }

        public static Storyboard AnimateWidth(this FrameworkElement element, double width, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.Width != width)
            {
                return AnimateDouble(element, "Width", element.Width, width, duration, easingFunction);
            }
            return null;
        }
        public static async Task AnimateWidthAsync(this FrameworkElement element, double width, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.Width != width)
            {
                await AnimateDoubleAsync(element, "Width", element.Width, width, duration, easingFunction);
            }
        }

        public static Storyboard AnimateHeight(this FrameworkElement element, double height, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.Height != height)
            {
                return AnimateDouble(element, "Height", element.Height, height, duration, easingFunction);
            }
            return null;
        }
        public static async Task AnimateHeightAsync(this FrameworkElement element, double height, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.Height != height)
            {
                await AnimateDoubleAsync(element, "Height", element.Height, height, duration, easingFunction);
            }
        }

        public static Storyboard FadeIn(this FrameworkElement element, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.Opacity < 1.0)
            {
                return AnimateDouble(element, "Opacity", element.Opacity, 1.0, duration, easingFunction);
            }
            return null;
        }
        public static async Task FadeInAsync(this FrameworkElement element, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.Opacity < 1.0)
            {
                await AnimateDoubleAsync(element, "Opacity", element.Opacity, 1.0, duration, easingFunction);
            }
        }

        public static Storyboard FadeOut(this FrameworkElement element, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.Opacity > 0.0)
            {
                return AnimateDouble(element, "Opacity", element.Opacity, 0.0, duration, easingFunction);
            }
            return null;
        }
        public static async Task FadeOutAsync(this FrameworkElement element, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.Opacity > 0.0)
            {
                await AnimateDoubleAsync(element, "Opacity", element.Opacity, 0.0, duration, easingFunction);
            }
        }
        public static Task AnimateDoubleAsync(this FrameworkElement element, string property, double from, double to, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
            Storyboard storyboard = element.AnimateDouble(property, from, to, duration, easingFunction);
            storyboard.Completed += (sender, e) =>
            {
                tcs.SetResult(true);
            };
            return tcs.Task;
        }
        public static Storyboard AnimateDouble(this FrameworkElement element, string property, double from, double to, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            var storyboard = new Storyboard();
            var animation = new DoubleAnimation
            {
                From = from,
                To = to,
                Duration = TimeSpan.FromMilliseconds(duration),
                EasingFunction = easingFunction ?? new SineEase(),
                FillBehavior = FillBehavior.HoldEnd,
                EnableDependentAnimation = true
            };<commit_msg>Fix AnimationExtensions<commit_after>﻿using System;
using System.Threading.Tasks;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media.Animation;

namespace AppStudio.Uwp
{
    public static class AnimationExtensions
    {
        public static Storyboard AnimateX(this FrameworkElement element, double x, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.GetTranslateX() != x)
            {
                return AnimateDoubleProperty(element.GetCompositeTransform(), "TranslateX", element.Width, x, duration, easingFunction);
            }
            return null;
        }
        public static async Task AnimateXAsync(this FrameworkElement element, double x, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.GetTranslateX() != x)
            {
                await AnimateDoublePropertyAsync(element.GetCompositeTransform(), "TranslateX", element.Width, x, duration, easingFunction);
            }
        }

        public static Storyboard AnimateY(this FrameworkElement element, double y, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.GetTranslateY() != y)
            {
                return AnimateDoubleProperty(element.GetCompositeTransform(), "TranslateY", element.Width, y, duration, easingFunction);
            }
            return null;
        }
        public static async Task AnimateYAsync(this FrameworkElement element, double y, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.GetTranslateY() != y)
            {
                await AnimateDoublePropertyAsync(element.GetCompositeTransform(), "TranslateY", element.Width, y, duration, easingFunction);
            }
        }

        public static Storyboard AnimateWidth(this FrameworkElement element, double width, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.Width != width)
            {
                return AnimateDouble(element, "Width", element.Width, width, duration, easingFunction);
            }
            return null;
        }
        public static async Task AnimateWidthAsync(this FrameworkElement element, double width, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.Width != width)
            {
                await AnimateDoubleAsync(element, "Width", element.Width, width, duration, easingFunction);
            }
        }

        public static Storyboard AnimateHeight(this FrameworkElement element, double height, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.Height != height)
            {
                return AnimateDouble(element, "Height", element.Height, height, duration, easingFunction);
            }
            return null;
        }
        public static async Task AnimateHeightAsync(this FrameworkElement element, double height, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.Height != height)
            {
                await AnimateDoubleAsync(element, "Height", element.Height, height, duration, easingFunction);
            }
        }

        public static Storyboard FadeIn(this FrameworkElement element, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.Opacity < 1.0)
            {
                return AnimateDouble(element, "Opacity", element.Opacity, 1.0, duration, easingFunction);
            }
            return null;
        }
        public static async Task FadeInAsync(this FrameworkElement element, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.Opacity < 1.0)
            {
                await AnimateDoubleAsync(element, "Opacity", element.Opacity, 1.0, duration, easingFunction);
            }
        }

        public static Storyboard FadeOut(this FrameworkElement element, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.Opacity > 0.0)
            {
                return AnimateDouble(element, "Opacity", element.Opacity, 0.0, duration, easingFunction);
            }
            return null;
        }
        public static async Task FadeOutAsync(this FrameworkElement element, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            if (element.Opacity > 0.0)
            {
                await AnimateDoubleAsync(element, "Opacity", element.Opacity, 0.0, duration, easingFunction);
            }
        }
        public static Task AnimateDoubleAsync(this FrameworkElement element, string property, double from, double to, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            return AnimateDoublePropertyAsync(element, property, from, to, duration, easingFunction);
        }
        public static Storyboard AnimateDouble(this FrameworkElement element, string property, double from, double to, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            return AnimateDoubleProperty(element, property, from, to, duration, easingFunction);
        }
        private static Task AnimateDoublePropertyAsync(DependencyObject element, string property, double from, double to, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
            Storyboard storyboard = AnimateDoubleProperty(element, property, from, to, duration, easingFunction);
            storyboard.Completed += (sender, e) =>
            {
                tcs.SetResult(true);
            };
            return tcs.Task;
        }
        public static Storyboard AnimateDoubleProperty(DependencyObject element, string property, double from, double to, double duration = 250, EasingFunctionBase easingFunction = null)
        {
            var storyboard = new Storyboard();
            var animation = new DoubleAnimation
            {
                From = from,
                To = to,
                Duration = TimeSpan.FromMilliseconds(duration),
                EasingFunction = easingFunction ?? new SineEase(),
                FillBehavior = FillBehavior.HoldEnd,
                EnableDependentAnimation = true
            };
{'fraction_non_alphanumeric': 0.07682162875041214, 'fraction_numerical': 0.010056050115397296, 'mean_word_length': 2.2217206585236324, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '366814', 'n_tokens_mistral': 3052, 'n_tokens_neox': 2874, 'n_words': 828}