<commit_before>//
//  KSGuideViewController.swift
//  KSGuideViewControllerDemo
//
//  Created by <NAME> on 2017/5/8.
//  Copyright © 2017年 <NAME>. All rights reserved.
//

import UIKit

public class KSGuideController: UIViewController {
    
    enum Region {
        case upperLeft
        case upperRight
        case lowerLeft
        case lowerRight
    }
    
    public typealias CompletionBlock = (() -> Void)
    public typealias IndexChangedBlock = ((_ index: Int, _ item: KSGuideItem) -> Void)
    
    private var items = [KSGuideItem]()
    private var currentIndex: Int = 0 {
        didSet {
            configViews()
        }
    }
    private var currentItem: KSGuideItem {
        get {
            return items[currentIndex]
        }
    }
    private let arrowImageView = UIImageView()
    private let textLabel = UILabel()
    private let maskLayer = CAShapeLayer()
    private var completion: CompletionBlock?
    private var indexChangedBlock: IndexChangedBlock?
    private var guideKey: String?
    
    public var maskCornerRadius: CGFloat = 5
    public var backgroundAlpha: CGFloat = 0.7
    public var spacing: CGFloat = 20
    public var padding: CGFloat = 50
    public var maskInsets = UIEdgeInsets(top: -8, left: -8, bottom: -8, right: -8)
    public var font = UIFont.systemFont(ofSize: 14)
    public var textColor = UIColor.white
    public var arrowColor = UIColor.white
    public var arrowImageName = "guide_arrow"
    public var animationDuration = 0.3
    public var animatedMask = true
    public var animatedText = true
    public var animatedArrow = true
    
    private var maskCenter: CGPoint {
        get {
            return CGPoint(x: hollowFrame.midX, y: hollowFrame.midY)
        }
    }
    
    private var region: Region {
        get {
            let center = maskCenter
            let bounds = view.bounds
            if center.x <= bounds.midX && center.y <= bounds.midY {
                return .upperLeft
            } else if center.x > bounds.midX && center.y <= bounds.midY {
                return .upperRight
            } else if center.x <= bounds.midX && center.y > bounds.midY {
                return .lowerLeft
            } else {
                return .lowerRight
            }
        }
    }
    
    private var hollowFrame: CGRect {
        get {
            var rect: CGRect
            if let sourceView = currentItem.sourceView {
                let systemVersion = (UIDevice.current.systemVersion as NSString).floatValue
                if systemVersion >= 8.0 && systemVersion < 9.0 {
                    rect = view.convert(sourceView.frame, from: sourceView.superview)
                } else {
                    rect = view.convert(sourceView.frame, from: sourceView.superview)
                }
            } else {
                rect = currentItem.rect
            }<commit_msg>Bug fixes<commit_after>//
//  KSGuideViewController.swift
//  KSGuideViewControllerDemo
//
//  Created by <NAME> on 2017/5/8.
//  Copyright © 2017年 <NAME>. All rights reserved.
//

import UIKit

public class KSGuideController: UIViewController {
    
    enum Region {
        case upperLeft
        case upperRight
        case lowerLeft
        case lowerRight
    }
    
    public typealias CompletionBlock = (() -> Void)
    public typealias IndexChangedBlock = ((_ index: Int, _ item: KSGuideItem) -> Void)
    
    private var items = [KSGuideItem]()
    private var currentIndex: Int = 0 {
        didSet {
            configViews()
        }
    }
    private var currentItem: KSGuideItem {
        get {
            return items[currentIndex]
        }
    }
    private let arrowImageView = UIImageView()
    private let textLabel = UILabel()
    private let maskLayer = CAShapeLayer()
    private var completion: CompletionBlock?
    private var indexChangedBlock: IndexChangedBlock?
    private var guideKey: String?
    
    public var maskCornerRadius: CGFloat = 5
    public var backgroundAlpha: CGFloat = 0.7
    public var spacing: CGFloat = 20
    public var padding: CGFloat = 50
    public var maskInsets = UIEdgeInsets(top: -8, left: -8, bottom: -8, right: -8)
    public var font = UIFont.systemFont(ofSize: 14)
    public var textColor = UIColor.white
    public var arrowColor = UIColor.white
    public var arrowImageName = "guide_arrow"
    public var animationDuration = 0.3
    public var animatedMask = true
    public var animatedText = true
    public var animatedArrow = true
    
    private var maskCenter: CGPoint {
        get {
            return CGPoint(x: hollowFrame.midX, y: hollowFrame.midY)
        }
    }
    
    private var region: Region {
        get {
            let center = maskCenter
            let bounds = view.bounds
            if center.x <= bounds.midX && center.y <= bounds.midY {
                return .upperLeft
            } else if center.x > bounds.midX && center.y <= bounds.midY {
                return .upperRight
            } else if center.x <= bounds.midX && center.y > bounds.midY {
                return .lowerLeft
            } else {
                return .lowerRight
            }
        }
    }
    
    private var hollowFrame: CGRect {
        get {
            var rect: CGRect
            if let sourceView = currentItem.sourceView {
                let systemVersion = (UIDevice.current.systemVersion as NSString).floatValue
                if systemVersion >= 8.0 && systemVersion < 9.0 {
                    rect = view.convert(sourceView.frame, from: sourceView.superview)
                } else {
                    // Unwrap the superView to ensure that we call `convert(_ rect: CGRect, from coordinateSpace: UICoordinateSpace) -> CGRect`
                    // instead of `convert(_ rect: CGRect, from view: UIView?) -> CGRect`
                    if let superView = sourceView.superview {
                        rect = view.convert(sourceView.frame, from: superView)
                    } else {
                        assertionFailure("sourceView must have a superView!")
                    }
                }
            } else {
                rect = currentItem.rect
            }
{'fraction_non_alphanumeric': 0.07968192145407335, 'fraction_numerical': 0.009737098344693282, 'mean_word_length': 1.807744874715262, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, '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': '119379', 'n_tokens_mistral': 1754, 'n_tokens_neox': 1633, 'n_words': 495}