<commit_before>//
//  UIViewExtension.swift
//  MerchantDashboard
//
//  Created by <NAME> on 3/16/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import UIKit

// MARK: Some frame value and class func
extension UIView {
    public var width: CGFloat {
        set { self.frame = CGRect(origin: frame.origin, size: CGSize(width: newValue, height: height)) }
        get { return self.frame.size.width }
    }
    
    public var height: CGFloat {
        set { self.frame = CGRect(origin: frame.origin, size: CGSize(width: width, height: newValue)) }
        get { return self.frame.size.height }
    }
    
    public var originX: CGFloat {
        set { self.frame.origin.x = newValue }
        get { return self.frame.origin.x }
    }
    
    public var originY: CGFloat {
        set { self.frame.origin.y = newValue }
        get { return self.frame.origin.y }
    }
    
    /// Create view from same name's nib
    ///
    /// - Returns: view
    public class func viewWithNib() -> Self? {
        return viewWithNibHelper()
    }
    
    fileprivate class func viewWithNibHelper<T>() -> T? {
        let viewsArray = Bundle.main.loadNibNamed(String(describing: self), owner: nil, options: nil)
        guard let viewArray = viewsArray else { return nil }
        if viewArray.count > 0 {
            return viewArray.first as? T
        }
        
        return nil
    }
    
    public func findFirstResponder() -> UIView? {
        guard !isFirstResponder else { return self }
        
        for subview in subviews {
            if let firstResponder = subview.findFirstResponder() {
                return firstResponder
            }
        }
        
        return nil
    }
    
    public func allSubViews() -> [UIView] {
        var subViews = self.subviews
        for v in subviews {
            subViews.append(contentsOf: v.allSubViews())
        }
        return subViews
    }

    /**
     Take snapshot of view as uiimage
     
     - returns: uiview contains snapshot image with shadow
     */
    public func snapshot() -> UIView? {
        UIGraphicsBeginImageContextWithOptions(self.bounds.size, false, 0.0)
        self.layer.render(in: UIGraphicsGetCurrentContext()!)
        let image = UIGraphicsGetImageFromCurrentImageContext()! as UIImage
        UIGraphicsEndImageContext()
        
        let cellSnapshot : UIView = UIImageView(image: image)
        let snapshotView = UIView(frame: cellSnapshot.frame)
        
        cellSnapshot.layer.masksToBounds = true
        cellSnapshot.layer.cornerRadius = 5
        
        //        cellSnapshot.layer.cornerRadius = 0.0
        snapshotView.layer.shadowOffset = CGSize(width: -5.0, height: 0.0)
        snapshotView.layer.shadowRadius = 5.0
        snapshotView.layer.shadowOpacity = 0.4
        
        snapshotView.addSubview(cellSnapshot)
        
        return snapshotView
    }
    
    /**
     Set gradient color
     
     - parameter startCol:   start color
     - parameter endCol:     end color
     - parameter startPoint: min 0 max 1
     - parameter endPoint:   min 0 max 1
     */
    public func setGradientBackground(color startCol: UIColor, endCol: UIColor, startPoint: CGPoint, endPoint: CGPoint) {
        let gradient: CAGradientLayer = CAGradientLayer()
        gradient.frame = self.bounds
        gradient.colors = [startCol.cgColor, endCol.cgColor]
        self.layer.insertSublayer(gradient, at: 0)
        gradient.startPoint = startPoint;
        gradient.endPoint = endPoint;
    }
    
    /// Add simple fadeTransition for the duration
    ///
    /// - Parameter duration: duration
    public func fadeTransition(_ duration:CFTimeInterval) {
        let animation:CATransition = CATransition()
        animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
        animation.type = CATransitionType.fade
        animation.duration = duration
        self.layer.add(animation, forKey: convertFromCATransitionType(CATransitionType.fade))
    }
    
    /// Custom corner radius
    ///
    /// - Parameters:
    ///   - corner: the corner to be rounded
    ///   - radius: radius
    public func customCornerRadius(_ corner: UIRectCorner, radius: CGSize) {
        let path = UIBezierPath(roundedRect:self.bounds, byRoundingCorners: corner, cornerRadii: radius)
        let maskLayer = CAShapeLayer()
        maskLayer.path = path.cgPath
        self.layer.mask = maskLayer
    }
    
    /// Set drop shadow for the view, if have corner radius then have to set it first
    /// Should call this during `viewDidLayoutSubview`
    ///
    /// - Parameters:
    ///   - shadowRadius: Shadow radius
    ///   - offset: Shadow offset
    public func setDropShadow(radius: CGFloat, offset: CGSize = .zero, color: UIColor? = nil) {
        layer.shadowRadius = radius;
        layer.masksToBounds = false;
        layer.shadowColor = (color ?? backgroundColor ?? tintColor).cgColor
        layer.shadowOffset = offset
        layer.shadowOpacity = 1
        let path = UIBezierPath(roundedRect: bounds, cornerRadius: layer.cornerRadius)
        layer.shadowPath = path.cgPath
    }
    
    public func getTopMostSuperView() -> UIView {
        if let v = self.superview {
            return v.getTopMostSuperView()
        }
        return self
    }
    
    public func maskRect(_ maskRect: CGRect, invert: Bool = false) {
        let maskLayer = CAShapeLayer()
        let path = CGMutablePath()
        if (invert) {
            path.addRect(bounds)
        }
        
        path.addRect(maskRect)
        maskLayer.path = path
        
        if (invert) {
            maskLayer.fillRule = CAShapeLayerFillRule.evenOdd
        }
        
        layer.mask = maskLayer;
    }
}

// MARK: - Some IBInspectable
extension UIView {
    @IBInspectable var cornerRadius: CGFloat {
        get {
            return layer.cornerRadius
        }
        set {
            layer.cornerRadius = newValue
            layer.masksToBounds = newValue > 0 ? true : false
        }
    }
    
    @IBInspectable var borderWidth: CGFloat {
        get {
            return layer.borderWidth
        }
        set {
            layer.borderWidth = newValue
        }
    }
    
    @IBInspectable var borderColor: UIColor? {
        get {
            guard let borderColor = layer.borderColor else { return nil }
            return UIColor(cgColor: borderColor)
        }
        set {
            layer.borderColor = newValue?.cgColor
        }
    }
    
    @IBInspectable var bgStartColor: UIColor? {
        get {
            return nil;
        }
        set {
            let gradient: CAGradientLayer = CAGradientLayer()
            gradient.frame = self.bounds
            gradient.colors = [newValue!.cgColor, backgroundColor!.cgColor]
            self.layer.insertSublayer(gradient, at: 0)
            gradient.startPoint = CGPoint(x: 0.5, y: 0)
            gradient.endPoint = CGPoint(x: 0.5, y: 1)
        }
    }
    
    //private var startGradientColorKey: UInt8 = 0 // We still need this boilerplate
    //private var endGradientColorKey: UInt8 = 1 // We still need this boilerplate
    //    @IBInspectable var bgStartColor: UIColor? {
    //        get {
    //            return objc_getAssociatedObject(self, &startGradientColorKey) as? UIColor
    //        }
    //        set(newValue) {
    //            objc_setAssociatedObject(self, &startGradientColorKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
    //        }
    //    }
    //
    //    @IBInspectable var bgEndColor: UIColor? {
    //        get {
    //            return objc_getAssociatedObject(self, &endGradientColorKey) as? UIColor
    //        }
    //        set(newValue) {
    //            objc_setAssociatedObject(self, &endGradientColorKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
    //        }
    //    }
}

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertFromCATransitionType(_ input: CATransitionType) -> String {
	return input.rawValue
}
<commit_msg>Update UIView+<commit_after>//
//  UIViewExtension.swift
//  MerchantDashboard
//
//  Created by <NAME> on 3/16/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import UIKit

// MARK: Some frame value and class func
extension UIView {
    public var width: CGFloat {
        set { self.frame = CGRect(origin: frame.origin, size: CGSize(width: newValue, height: height)) }
        get { return self.frame.size.width }
    }
    
    public var height: CGFloat {
        set { self.frame = CGRect(origin: frame.origin, size: CGSize(width: width, height: newValue)) }
        get { return self.frame.size.height }
    }
    
    public var originX: CGFloat {
        set { self.frame.origin.x = newValue }
        get { return self.frame.origin.x }
    }
    
    public var originY: CGFloat {
        set { self.frame.origin.y = newValue }
        get { return self.frame.origin.y }
    }
    
    /// Create view from same name's nib
    ///
    /// - Returns: view
    public class func viewWithNib() -> Self? {
        return viewWithNibHelper()
    }
    
    fileprivate class func viewWithNibHelper<T>() -> T? {
        let viewsArray = Bundle.main.loadNibNamed(String(describing: self), owner: nil, options: nil)
        guard let viewArray = viewsArray else { return nil }
        if viewArray.count > 0 {
            return viewArray.first as? T
        }
        
        return nil
    }
    
    public func findFirstResponder() -> UIView? {
        guard !isFirstResponder else { return self }
        
        for subview in subviews {
            if let firstResponder = subview.findFirstResponder() {
                return firstResponder
            }
        }
        
        return nil
    }
    
    public func allSubViews() -> [UIView] {
        var subViews = self.subviews
        for v in subviews {
            subViews.append(contentsOf: v.allSubViews())
        }
        return subViews
    }

    /**
     Take snapshot of view as uiimage
     
     - returns: uiview contains snapshot image with shadow
     */
    public func snapshot() -> UIView? {
        UIGraphicsBeginImageContextWithOptions(self.bounds.size, false, 0.0)
        self.layer.render(in: UIGraphicsGetCurrentContext()!)
        let image = UIGraphicsGetImageFromCurrentImageContext()! as UIImage
        UIGraphicsEndImageContext()
        
        let cellSnapshot : UIView = UIImageView(image: image)
        let snapshotView = UIView(frame: cellSnapshot.frame)
        
        cellSnapshot.layer.masksToBounds = true
        cellSnapshot.layer.cornerRadius = 5
        
        //        cellSnapshot.layer.cornerRadius = 0.0
        snapshotView.layer.shadowOffset = CGSize(width: -5.0, height: 0.0)
        snapshotView.layer.shadowRadius = 5.0
        snapshotView.layer.shadowOpacity = 0.4
        
        snapshotView.addSubview(cellSnapshot)
        
        return snapshotView
    }
    
    /**
     Set gradient color
     
     - parameter startCol:   start color
     - parameter endCol:     end color
     - parameter startPoint: min 0 max 1
     - parameter endPoint:   min 0 max 1
     */
    public func setGradientBackground(color startCol: UIColor, endCol: UIColor, startPoint: CGPoint, endPoint: CGPoint) {
        let gradient: CAGradientLayer = CAGradientLayer()
        gradient.frame = self.bounds
        gradient.colors = [startCol.cgColor, endCol.cgColor]
        self.layer.insertSublayer(gradient, at: 0)
        gradient.startPoint = startPoint;
        gradient.endPoint = endPoint;
    }
    
    /// Add simple fadeTransition for the duration
    ///
    /// - Parameter duration: duration
    public func fadeTransition(_ duration:CFTimeInterval) {
        let animation:CATransition = CATransition()
        animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
        animation.type = CATransitionType.fade
        animation.duration = duration
        self.layer.add(animation, forKey: convertFromCATransitionType(CATransitionType.fade))
    }
    
    /// Custom corner radius
    ///
    /// - Parameters:
    ///   - corner: the corner to be rounded
    ///   - radius: radius
    public func customCornerRadius(_ corner: UIRectCorner, radius: CGFloat) {
        let path = UIBezierPath(roundedRect:self.bounds, byRoundingCorners: corner, cornerRadii: CGSize(width: radius, height: radius))
        let maskLayer = CAShapeLayer()
        maskLayer.path = path.cgPath
        self.layer.mask = maskLayer
    }
    
    /// Set drop shadow for the view, if have corner radius then have to set it first
    /// Should call this during `viewDidLayoutSubview`
    ///
    /// - Parameters:
    ///   - shadowRadius: Shadow radius
    ///   - offset: Shadow offset
    public func setDropShadow(radius: CGFloat, offset: CGSize = .zero, color: UIColor? = nil) {
        layer.shadowRadius = radius;
        layer.masksToBounds = false;
        layer.shadowColor = (color ?? backgroundColor ?? tintColor).cgColor
        layer.shadowOffset = offset
        layer.shadowOpacity = 1
        let path = UIBezierPath(roundedRect: bounds, cornerRadius: layer.cornerRadius)
        layer.shadowPath = path.cgPath
    }
    
    public func getTopMostSuperView() -> UIView {
        if let v = self.superview {
            return v.getTopMostSuperView()
        }
        return self
    }
    
    public func maskRect(_ maskRect: CGRect, invert: Bool = false) {
        let maskLayer = CAShapeLayer()
        let path = CGMutablePath()
        if (invert) {
            path.addRect(bounds)
        }
        
        path.addRect(maskRect)
        maskLayer.path = path
        
        if (invert) {
            maskLayer.fillRule = CAShapeLayerFillRule.evenOdd
        }
        
        layer.mask = maskLayer;
    }
}

// MARK: - Some IBInspectable
extension UIView {
    @IBInspectable var cornerRadius: CGFloat {
        get {
            return layer.cornerRadius
        }
        set {
            layer.cornerRadius = newValue
            layer.masksToBounds = newValue > 0 ? true : false
        }
    }
    
    @IBInspectable var borderWidth: CGFloat {
        get {
            return layer.borderWidth
        }
        set {
            layer.borderWidth = newValue
        }
    }
    
    @IBInspectable var borderColor: UIColor? {
        get {
            guard let borderColor = layer.borderColor else { return nil }
            return UIColor(cgColor: borderColor)
        }
        set {
            layer.borderColor = newValue?.cgColor
        }
    }
    
    @IBInspectable var bgStartColor: UIColor? {
        get {
            return nil;
        }
        set {
            let gradient: CAGradientLayer = CAGradientLayer()
            gradient.frame = self.bounds
            gradient.colors = [newValue!.cgColor, backgroundColor!.cgColor]
            self.layer.insertSublayer(gradient, at: 0)
            gradient.startPoint = CGPoint(x: 0.5, y: 0)
            gradient.endPoint = CGPoint(x: 0.5, y: 1)
        }
    }
    
    //private var startGradientColorKey: UInt8 = 0 // We still need this boilerplate
    //private var endGradientColorKey: UInt8 = 1 // We still need this boilerplate
    //    @IBInspectable var bgStartColor: UIColor? {
    //        get {
    //            return objc_getAssociatedObject(self, &startGradientColorKey) as? UIColor
    //        }
    //        set(newValue) {
    //            objc_setAssociatedObject(self, &startGradientColorKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
    //        }
    //    }
    //
    //    @IBInspectable var bgEndColor: UIColor? {
    //        get {
    //            return objc_getAssociatedObject(self, &endGradientColorKey) as? UIColor
    //        }
    //        set(newValue) {
    //            objc_setAssociatedObject(self, &endGradientColorKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
    //        }
    //    }
}

// Helper function inserted by Swift 4.2 migrator.
fileprivate func convertFromCATransitionType(_ input: CATransitionType) -> String {
	return input.rawValue
}

{'fraction_non_alphanumeric': 0.09066830920850015, 'fraction_numerical': 0.005297197412996613, 'mean_word_length': 1.9709057639524246, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 27, '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': '4848082', 'n_tokens_mistral': 4838, 'n_tokens_neox': 4651, 'n_words': 1130}