<commit_before>//
//  CoachMarksView.swift
//  CoachMarksExample
//
//  Created by <NAME> on 6/15/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation
import UIKit

let kAnimationDuration = 0.3
let kCutoutRadius = 2.0
let kMaxLblWidth = 230.0
let kLblSpacing = 35.0

protocol CoachMarksViewDelegate: class {
    func coachMarksView(_ coachMarksView: CoachMarksView, willNavigateTo index: Int)
    func coachMarksView(_ coachMarksView: CoachMarksView, didNavigateTo index: Int)
    func coachMarksViewWillCleanup(_ coachMarksView: CoachMarksView)
    func coachMarksViewDidCleanup(_ coachMarksView: CoachMarksView)
    func didTap(at index: Int)
}

class CoachMarksView: UIView {
    
    typealias CoachMark = [String:Any]
    
    var focusView: FocusView?
    var bubble: BubbleView?
    
    var shapeLayerMask: CAShapeLayer
    var markIndex: Int = 0
//    var lblContinue: UILabel
    weak var delegate: CoachMarksViewDelegate?
    var coachMarks: [CoachMark]
    var maskColor: UIColor = UIColor.white
    var animationDuration: CGFloat = 0.3
    var cutoutRadius: CGFloat = CGFloat(kCutoutRadius)
    var maxLblWidth: CGFloat = CGFloat(kMaxLblWidth)
    var lblSpacing: CGFloat = CGFloat(kLblSpacing)
    var useBubbles: Bool = true
    
    init(frame: CGRect, coachMarks: [CoachMark]) {
        
        self.coachMarks = coachMarks
        self.shapeLayerMask = CAShapeLayer()
        
        super.init(frame: frame)
        setup()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setup() {
        // Shape layer mask
        shapeLayerMask.fillRule = kCAFillRuleEvenOdd
        shapeLayerMask.fillColor = UIColor(white: 0.0, alpha: 0.8).cgColor
        layer.addSublayer(shapeLayerMask)
        
        // Capture touches
        let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(userDidTap(_:)))
        let swipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(userDidTap(_:)))
        swipeGestureRecognizer.direction = [.left, .right]
        addGestureRecognizer(swipeGestureRecognizer)
        addGestureRecognizer(tapGestureRecognizer)

        // Hide until invoked
        isHidden = true
    }
    
    // MARK: Cutout Modify
    func setCutout(to rect: CGRect, with shape: String) {
        // Define shape
        let maskPath = UIBezierPath(rect: bounds)
        let cutoutPath: UIBezierPath
        
        if (shape == "circle") {
            cutoutPath = UIBezierPath(ovalIn: rect)
        } else if (shape == "square") {
            cutoutPath = UIBezierPath(rect: rect)
        } else {
            cutoutPath = UIBezierPath(roundedRect: rect, cornerRadius: cutoutRadius)
        }
        
        maskPath.append(cutoutPath)
        
        // Set the new path
        shapeLayerMask.path = maskPath.cgPath
        
    }
    
    func animateCutout(to rect: CGRect, with shape: String) {
        // Define shape
        let maskPath = UIBezierPath(rect: bounds)
        let cutoutPath: UIBezierPath
        
        if shape == "circle" {
            cutoutPath = UIBezierPath(ovalIn: rect)
        } else if shape == "square" {
            cutoutPath = UIBezierPath(rect: rect)
        } else {
            cutoutPath = UIBezierPath(roundedRect: rect, cornerRadius: cutoutRadius)
        }
        
        maskPath.append(cutoutPath)
        
        // Animate it
        let anim = CABasicAnimation(keyPath: "path")
        anim.delegate = self
        anim.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
        anim.duration = CFTimeInterval(animationDuration)
        anim.isRemovedOnCompletion = false
        anim.fillMode = kCAFillModeForwards
        anim.fromValue = shapeLayerMask.mask
        anim.toValue = maskPath.cgPath
        shapeLayerMask.add(anim, forKey: "path")
        shapeLayerMask.path = maskPath.cgPath
    }
 
    // MARK: Mask Color
    func setMaskColor(color: UIColor) {
        maskColor = color
        shapeLayerMask.fillColor = maskColor.cgColor
    }

    func userDidTap(_ recognizer: UIGestureRecognizer) {
        delegate?.didTap(at: markIndex)
        
        // Go to the next coach mark
         goToCoachmark(index: markIndex+1)
    }
    
    func start() {
        // Fade in self
        alpha = 0.0<commit_msg>[#2] Fix animating between cutouts<commit_after>//
//  CoachMarksView.swift
//  CoachMarksExample
//
//  Created by <NAME> on 6/15/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation
import UIKit

let kAnimationDuration = 0.3
let kCutoutRadius = 2.0
let kMaxLblWidth = 230.0
let kLblSpacing = 35.0

protocol CoachMarksViewDelegate: class {
    func coachMarksView(_ coachMarksView: CoachMarksView, willNavigateTo index: Int)
    func coachMarksView(_ coachMarksView: CoachMarksView, didNavigateTo index: Int)
    func coachMarksViewWillCleanup(_ coachMarksView: CoachMarksView)
    func coachMarksViewDidCleanup(_ coachMarksView: CoachMarksView)
    func didTap(at index: Int)
}

class CoachMarksView: UIView {
    
    typealias CoachMark = [String:Any]
    
    var focusView: FocusView?
    var bubble: BubbleView?
    
    var shapeLayerMask: CAShapeLayer
    var markIndex: Int = 0
//    var lblContinue: UILabel
    weak var delegate: CoachMarksViewDelegate?
    var coachMarks: [CoachMark]
    var maskColor: UIColor = UIColor.white
    var animationDuration: CGFloat = 0.3
    var cutoutRadius: CGFloat = CGFloat(kCutoutRadius)
    var maxLblWidth: CGFloat = CGFloat(kMaxLblWidth)
    var lblSpacing: CGFloat = CGFloat(kLblSpacing)
    var useBubbles: Bool = true
    
    init(frame: CGRect, coachMarks: [CoachMark]) {
        
        self.coachMarks = coachMarks
        self.shapeLayerMask = CAShapeLayer()
        
        super.init(frame: frame)
        setup()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setup() {
        // Shape layer mask
        shapeLayerMask.fillRule = kCAFillRuleEvenOdd
        shapeLayerMask.fillColor = UIColor(white: 0.0, alpha: 0.8).cgColor
        layer.addSublayer(shapeLayerMask)
        
        // Capture touches
        let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(userDidTap(_:)))
        let swipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(userDidTap(_:)))
        swipeGestureRecognizer.direction = [.left, .right]
        addGestureRecognizer(swipeGestureRecognizer)
        addGestureRecognizer(tapGestureRecognizer)

        // Hide until invoked
        isHidden = true
    }
    
    // MARK: Cutout Modify
    func setCutout(to rect: CGRect, with shape: String) {
        // Define shape
        let maskPath = UIBezierPath(rect: bounds)
        let cutoutPath: UIBezierPath
        
        if (shape == "circle") {
            cutoutPath = UIBezierPath(ovalIn: rect)
        } else if (shape == "square") {
            cutoutPath = UIBezierPath(rect: rect)
        } else {
            cutoutPath = UIBezierPath(roundedRect: rect, cornerRadius: cutoutRadius)
        }
        
        maskPath.append(cutoutPath)
        
        // Set the new path
        shapeLayerMask.path = maskPath.cgPath
        
    }
    
    func animateCutout(to rect: CGRect, with shape: String) {
        // Define shape
        let maskPath = UIBezierPath(rect: bounds)
        let cutoutPath: UIBezierPath
        
        if shape == "circle" {
            cutoutPath = UIBezierPath(ovalIn: rect)
        } else if shape == "square" {
            cutoutPath = UIBezierPath(rect: rect)
        } else {
            cutoutPath = UIBezierPath(roundedRect: rect, cornerRadius: cutoutRadius)
        }
        
        maskPath.append(cutoutPath)
        
        // Animate it
        let anim = CABasicAnimation(keyPath: "path")
        anim.delegate = self
        anim.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut)
        anim.duration = CFTimeInterval(animationDuration)
        anim.isRemovedOnCompletion = false
        anim.fillMode = kCAFillModeForwards
        anim.fromValue = shapeLayerMask.path
        anim.toValue = maskPath.cgPath
        shapeLayerMask.add(anim, forKey: "path")
        shapeLayerMask.path = maskPath.cgPath
    }
 
    // MARK: Mask Color
    func setMaskColor(color: UIColor) {
        maskColor = color
        shapeLayerMask.fillColor = maskColor.cgColor
    }

    func userDidTap(_ recognizer: UIGestureRecognizer) {
        delegate?.didTap(at: markIndex)
        
        // Go to the next coach mark
         goToCoachmark(index: markIndex+1)
    }
    
    func start() {
        // Fade in self
        alpha = 0.0
{'fraction_non_alphanumeric': 0.08421171936982885, 'fraction_numerical': 0.006913748158222826, 'mean_word_length': 2.445529090199141, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6033625', 'n_tokens_mistral': 2842, 'n_tokens_neox': 2718, 'n_words': 619}