<commit_before>////////////////////////////////////////////////////////////////////////////////
//
//  Fork unstable media GmbH
//  Copyright 2006-2008 Fork unstable media GmbH
//  All Rights Reserved.
//
//  NOTICE: Fork unstable media permits you to use, modify, and distribute this
//  file in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////

package reprise.css.transitions
{
	import reprise.core.reprise;
	import reprise.css.CSSDeclaration;
	import reprise.css.CSSParsingResult;
	import reprise.css.CSSProperty;
	import reprise.css.CSSPropertyCache;
	import reprise.events.TransitionEvent;
	
	import com.robertpenner.easing.Linear;
	
	import flash.events.EventDispatcher;
	import flash.utils.getTimer;
	
	use namespace reprise;
	
	public class CSSTransitionsManager
	{
		/***************************************************************************
		*							protected properties							   *
		***************************************************************************/
		protected static const DEFAULT_DURATION : Array = initDefaultDuration();
		protected static const DEFAULT_DELAY : Array = initDefaultDelay();
		protected static const DEFAULT_EASING : Array = [Linear.easeNone];
		protected static var g_transitionShortcuts : Object = {};
		
		protected var m_transitionProperties : Array;
		protected var m_transitionDurations : Array;
		protected var m_transitionDelays : Array;
		protected var m_transitionEasings : Array;
		protected var m_defaultValues : Array;
		
		protected var m_activeTransitions : Object;
		protected var m_target : EventDispatcher;
		protected var m_frameDuration : int;

		
		/***************************************************************************
		*							public methods								   *
		***************************************************************************/
		public function CSSTransitionsManager(target : EventDispatcher)
		{
			m_target = target;
		}
		
		public function isActive() : Boolean
		{
			return m_activeTransitions != null;
		}
		
		public function hasTransitionForStyle(style : String) : Boolean
		{
			return m_transitionProperties && m_transitionProperties.indexOf(style) != -1;
		}
		
		public function hasActiveTransitionForStyle(style : String) : Boolean
		{
			return m_activeTransitions && m_activeTransitions[style] != null;
		}

		public function processTransitions(oldStyles : CSSDeclaration, newStyles : CSSDeclaration, 
			frameRate : int) : CSSDeclaration
		{
			var transitionPropName : String;
			var transitionDuration : CSSProperty;
			var transitionDelay : CSSProperty;
			var transitionEasing : Function;
			var transition : CSSPropertyTransition;
			var startTime : int = getTimer();
			
			if (newStyles.hasStyle('transitionFrameDropping') && 
				newStyles.getStyle('transitionFrameDropping').specifiedValue() == 'prevent')
			{
				m_frameDuration = 1000 / frameRate;
			}
			else
			{
				m_frameDuration = 10000;
			}
			if (newStyles && newStyles.getStyle('RepriseTransitionProperty'))
			{
				m_transitionProperties = 
					newStyles.getStyle('RepriseTransitionProperty').specifiedValue();
				m_transitionDurations = newStyles.hasStyle('RepriseTransitionDuration') 
					? newStyles.getStyle('RepriseTransitionDuration').specifiedValue() 
					: DEFAULT_DURATION;
				m_transitionDelays = newStyles.hasStyle('RepriseTransitionDelay') 
					? newStyles.getStyle('RepriseTransitionDelay').specifiedValue() 
					: DEFAULT_DELAY;
				m_transitionEasings = 
					newStyles.hasStyle('RepriseTransitionTimingFunction') 
					? newStyles.getStyle('RepriseTransitionTimingFunction').specifiedValue() 
					: DEFAULT_EASING;
				m_defaultValues = newStyles.getStyle(
					'RepriseTransitionDefaultValue').specifiedValue();
				
				//remove any transitions that aren't supposed to be active anymore
				if (m_activeTransitions)
				{
					for (transitionPropName in m_activeTransitions)
					{
						//TODO: check if the shortcut check can also use g_transitionShortcuts here
						if (m_transitionProperties.indexOf(transitionPropName) == -1)
						{
							transition = m_activeTransitions[transitionPropName];
							var shortcut : String = transition.shortcut;
							if (!shortcut || m_transitionProperties.indexOf(shortcut) == -1)
							{
								delete m_activeTransitions[transitionPropName];
								var cancelEvent : TransitionEvent = new TransitionEvent(
									TransitionEvent.TRANSITION_CANCEL);
								cancelEvent.propertyName = transitionPropName;
								cancelEvent.elapsedTime = startTime - 
									transition.startTime - 
									transition.delay.specifiedValue();
								m_target.dispatchEvent(cancelEvent);
							}
						}
					}
				}
				else
				{
					m_activeTransitions = {};
				}
				
				function processProperty(transitionPropName : String, 
					shortcut : String = null, defaultValue : CSSProperty = null) : void
				{
					var oldValue : CSSProperty = (oldStyles && oldStyles.getStyle(transitionPropName)) as CSSProperty;
					var targetValue : CSSProperty = 
						newStyles.getStyle(transitionPropName);
					
					//apply default values
					if (defaultValue && defaultValue.specifiedValue() != 'none')
					{
						//use default value if we have a target value but no old value
						if (targetValue && !oldValue)
						{
							oldValue = defaultValue;
						}
						//use default value if we have an old value but no target value
						else if (oldValue && !targetValue)
						{
							targetValue = defaultValue;
						}
					}
					
					//ignore properties that don't have previous values or target values
					//TODO: check if we can implement default values for new elements
					if (!oldValue || !targetValue || 
						oldValue.specifiedValue() == targetValue.specifiedValue())
					{
						return;
					}
					transition = m_activeTransitions[transitionPropName];
					if (!transition)
					{
						transition = new CSSPropertyTransition(
							transitionPropName, shortcut);
						transition.duration = transitionDuration;
						transition.delay = transitionDelay;
						transition.easing = transitionEasing;
						transition.startTime = startTime;
						transition.startValue = oldValue;
						transition.endValue = targetValue;
						m_activeTransitions[transitionPropName] = transition;
					}
					else if (transition.endValue != targetValue)
					{
						transition.easing = transitionEasing;
						transition.updateValues(targetValue, transitionDuration, 
							transitionDelay, startTime, m_frameDuration, this);
					}
				}
				
				//add all new properties and update already active ones
				for (var i : int = 0; i < m_transitionProperties.length; i++)
				{
					transitionPropName = m_transitionProperties[i];
					transitionDuration = m_transitionDurations[i] || 
						transitionDuration || DEFAULT_DURATION[0];
					transitionDelay = m_transitionDelays[i] || transitionDelay || DEFAULT_DELAY[0];
					transitionEasing = m_transitionEasings[i] || 
						transitionEasing || DEFAULT_EASING[0];
					var defaultValue : *;
					if (m_defaultValues[i] && m_defaultValues[i] != 'none')
					{
						defaultValue = CSSPropertyCache.propertyForKeyValue(
							transitionPropName, m_defaultValues[i], null);
					}
					if (g_transitionShortcuts[transitionPropName])
					{
						var expansions : Array = 
							g_transitionShortcuts[transitionPropName];
						if (defaultValue)
						{
							var defaultValuesForExpansions : CSSParsingResult = 
								CSSParsingResult(defaultValue);
							var name : String;
							for each (name in expansions)
							{
								processProperty(name, transitionPropName, 
									defaultValuesForExpansions.propertyForKey(name));
							}<commit_msg>- bugfix: setting a default value of 'none' didn't work for CSS transitions of the 'display' property<commit_after>////////////////////////////////////////////////////////////////////////////////
//
//  Fork unstable media GmbH
//  Copyright 2006-2008 Fork unstable media GmbH
//  All Rights Reserved.
//
//  NOTICE: Fork unstable media permits you to use, modify, and distribute this
//  file in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////

package reprise.css.transitions
{
	import reprise.core.reprise;
	import reprise.css.CSSDeclaration;
	import reprise.css.CSSParsingResult;
	import reprise.css.CSSProperty;
	import reprise.css.CSSPropertyCache;
	import reprise.events.TransitionEvent;
	
	import com.robertpenner.easing.Linear;
	
	import flash.events.EventDispatcher;
	import flash.utils.getTimer;
	
	use namespace reprise;
	
	public class CSSTransitionsManager
	{
		/***************************************************************************
		*							protected properties							   *
		***************************************************************************/
		protected static const DEFAULT_DURATION : Array = initDefaultDuration();
		protected static const DEFAULT_DELAY : Array = initDefaultDelay();
		protected static const DEFAULT_EASING : Array = [Linear.easeNone];
		protected static var g_transitionShortcuts : Object = {};
		
		protected var m_transitionProperties : Array;
		protected var m_transitionDurations : Array;
		protected var m_transitionDelays : Array;
		protected var m_transitionEasings : Array;
		protected var m_defaultValues : Array;
		
		protected var m_activeTransitions : Object;
		protected var m_target : EventDispatcher;
		protected var m_frameDuration : int;

		
		/***************************************************************************
		*							public methods								   *
		***************************************************************************/
		public function CSSTransitionsManager(target : EventDispatcher)
		{
			m_target = target;
		}
		
		public function isActive() : Boolean
		{
			return m_activeTransitions != null;
		}
		
		public function hasTransitionForStyle(style : String) : Boolean
		{
			return m_transitionProperties && m_transitionProperties.indexOf(style) != -1;
		}
		
		public function hasActiveTransitionForStyle(style : String) : Boolean
		{
			return m_activeTransitions && m_activeTransitions[style] != null;
		}

		public function processTransitions(oldStyles : CSSDeclaration, newStyles : CSSDeclaration, 
			frameRate : int) : CSSDeclaration
		{
			var transitionPropName : String;
			var transitionDuration : CSSProperty;
			var transitionDelay : CSSProperty;
			var transitionEasing : Function;
			var transition : CSSPropertyTransition;
			var startTime : int = getTimer();
			
			if (newStyles.hasStyle('transitionFrameDropping') && 
				newStyles.getStyle('transitionFrameDropping').specifiedValue() == 'prevent')
			{
				m_frameDuration = 1000 / frameRate;
			}
			else
			{
				m_frameDuration = 10000;
			}
			if (newStyles && newStyles.getStyle('RepriseTransitionProperty'))
			{
				m_transitionProperties = 
					newStyles.getStyle('RepriseTransitionProperty').specifiedValue();
				m_transitionDurations = newStyles.hasStyle('RepriseTransitionDuration') 
					? newStyles.getStyle('RepriseTransitionDuration').specifiedValue() 
					: DEFAULT_DURATION;
				m_transitionDelays = newStyles.hasStyle('RepriseTransitionDelay') 
					? newStyles.getStyle('RepriseTransitionDelay').specifiedValue() 
					: DEFAULT_DELAY;
				m_transitionEasings = 
					newStyles.hasStyle('RepriseTransitionTimingFunction') 
					? newStyles.getStyle('RepriseTransitionTimingFunction').specifiedValue() 
					: DEFAULT_EASING;
				m_defaultValues = newStyles.getStyle(
					'RepriseTransitionDefaultValue').specifiedValue();
				
				//remove any transitions that aren't supposed to be active anymore
				if (m_activeTransitions)
				{
					for (transitionPropName in m_activeTransitions)
					{
						//TODO: check if the shortcut check can also use g_transitionShortcuts here
						if (m_transitionProperties.indexOf(transitionPropName) == -1)
						{
							transition = m_activeTransitions[transitionPropName];
							var shortcut : String = transition.shortcut;
							if (!shortcut || m_transitionProperties.indexOf(shortcut) == -1)
							{
								delete m_activeTransitions[transitionPropName];
								var cancelEvent : TransitionEvent = new TransitionEvent(
									TransitionEvent.TRANSITION_CANCEL);
								cancelEvent.propertyName = transitionPropName;
								cancelEvent.elapsedTime = startTime - 
									transition.startTime - 
									transition.delay.specifiedValue();
								m_target.dispatchEvent(cancelEvent);
							}
						}
					}
				}
				else
				{
					m_activeTransitions = {};
				}
				
				function processProperty(transitionPropName : String, 
					shortcut : String = null, defaultValue : CSSProperty = null) : void
				{
					var oldValue : CSSProperty = (oldStyles && oldStyles.getStyle(transitionPropName)) as CSSProperty;
					var targetValue : CSSProperty = 
						newStyles.getStyle(transitionPropName);
					
					//apply default values
					if (defaultValue && (defaultValue.specifiedValue() != 'none' || 
						transitionPropName == 'display'))
					{
						//use default value if we have a target value but no old value
						if (targetValue && !oldValue)
						{
							oldValue = defaultValue;
						}
						//use default value if we have an old value but no target value
						else if (oldValue && !targetValue)
						{
							targetValue = defaultValue;
						}
					}
					
					//ignore properties that don't have previous values or target values
					//TODO: check if we can implement default values for new elements
					if (!oldValue || !targetValue || 
						oldValue.specifiedValue() == targetValue.specifiedValue())
					{
						return;
					}
					transition = m_activeTransitions[transitionPropName];
					if (!transition)
					{
						transition = new CSSPropertyTransition(
							transitionPropName, shortcut);
						transition.duration = transitionDuration;
						transition.delay = transitionDelay;
						transition.easing = transitionEasing;
						transition.startTime = startTime;
						transition.startValue = oldValue;
						transition.endValue = targetValue;
						m_activeTransitions[transitionPropName] = transition;
					}
					else if (transition.endValue != targetValue)
					{
						transition.easing = transitionEasing;
						transition.updateValues(targetValue, transitionDuration, 
							transitionDelay, startTime, m_frameDuration, this);
					}
				}
				
				//add all new properties and update already active ones
				for (var i : int = 0; i < m_transitionProperties.length; i++)
				{
					transitionPropName = m_transitionProperties[i];
					transitionDuration = m_transitionDurations[i] || 
						transitionDuration || DEFAULT_DURATION[0];
					transitionDelay = m_transitionDelays[i] || transitionDelay || DEFAULT_DELAY[0];
					transitionEasing = m_transitionEasings[i] || 
						transitionEasing || DEFAULT_EASING[0];
					var defaultValue : *;
					if (m_defaultValues[i] && (m_defaultValues[i] != 'none' || 
						transitionPropName == 'display'))
					{
						defaultValue = CSSPropertyCache.propertyForKeyValue(
							transitionPropName, m_defaultValues[i], null);
					}
					if (g_transitionShortcuts[transitionPropName])
					{
						var expansions : Array = 
							g_transitionShortcuts[transitionPropName];
						if (defaultValue)
						{
							var defaultValuesForExpansions : CSSParsingResult = 
								CSSParsingResult(defaultValue);
							var name : String;
							for each (name in expansions)
							{
								processProperty(name, transitionPropName, 
									defaultValuesForExpansions.propertyForKey(name));
							}
{'fraction_non_alphanumeric': 0.13781437507979064, 'fraction_numerical': 0.003063960168517809, 'mean_word_length': 3.1778666666666666, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2363713', 'n_tokens_mistral': 5539, 'n_tokens_neox': 4011, 'n_words': 942}