File

projects/wms-framework/src/lib/helpers/Animation.ts

Description

Base class for timeline objets

Extends

DependencyObject

Index

Properties
Methods

Constructor

constructor()

Creates an instance of TimelineModel.

Properties

BeginTime
Type : TimeRange

Start time

Public Completed
Type : SubscriptionEvent<any>

Event to be triggered when the storyboard completes

Protected bindingExpressions
Default value : new SimpleDictionary< string, BindingExpression >()
Inherited from DependencyObject
Public BindingValidationError
Default value : new SubscriptionEvent< (sender: any, e: BindingValidationErrorEventArgs) => void >()
Inherited from DependencyObject

Event for validation errors

Public change
Type : SubscriptionEvent<void>
Default value : new SubscriptionEvent()
Inherited from DependencyObject

Infrastructure event for notifying event changes

Public Dispatcher
Type : Dispatcher
Default value : Dispatcher.GetDispatcher()
Inherited from DependencyObject
isEnableSetPropertiesRegistry
Type : boolean
Default value : true
Inherited from DependencyObject

Flag which indicates if the dependency property set mechanism is enable

Public IsInitializingBindings
Type : boolean
Default value : false
Inherited from DependencyObject

Property to determine if bindings are being initialized

previousValidationMessage
Type : string
Default value : ''
Inherited from DependencyObject
Protected properties
Type : object
Default value : {}
Inherited from DependencyObject
Private setPropertiesRegistry
Type : Map<string | boolean>
Default value : new Map()
Inherited from DependencyObject

Registry with dependencies properties which has been set

validationerr
Default value : false
Inherited from DependencyObject
validationMessagesStack
Type : Array<>
Default value : []
Inherited from DependencyObject

Keeps a queue of validation messages registered on the current Dependency Object

Methods

Execute
Execute()

Executes the animation frames

Returns : void
Private addRelatedSubscriptionIfRequired
addRelatedSubscriptionIfRequired(event: SubscriptionEvent<any>, theHandler: any, bindingExpression: BindingExpression)
Inherited from DependencyObject
Parameters :
Name Type Optional
event SubscriptionEvent<any> No
theHandler any No
bindingExpression BindingExpression No
Returns : void
Private addSubscriptionForTwoWayBindings
addSubscriptionForTwoWayBindings(dependencyProperty: DependencyProperty, binding: Binding, bindingExpression: BindingExpression)
Inherited from DependencyObject
Parameters :
Name Type Optional
dependencyProperty DependencyProperty No
binding Binding No
bindingExpression BindingExpression No
Returns : void
addsValidationMessage
addsValidationMessage(propKey: Binding | string, message: string)
Inherited from DependencyObject

Adds a new validation message associated to a binding or a property name

Parameters :
Name Type Optional
propKey Binding | string No
message string No
Returns : void
Private beginSubscribeToMultiPropertyPathChanges
beginSubscribeToMultiPropertyPathChanges(context: any, binding: Binding, dependencyProperty: DependencyProperty, bindingExpression: BindingExpression)
Inherited from DependencyObject
Parameters :
Name Type Optional
context any No
binding Binding No
dependencyProperty DependencyProperty No
bindingExpression BindingExpression No
Returns : void
Private checkForSubscriptoinToDataErrorInfo
checkForSubscriptoinToDataErrorInfo(currentContext: any, binding: Binding, propertyToSubscribe: string, bindingExpression: BindingExpression)
Inherited from DependencyObject
Parameters :
Name Type Optional
currentContext any No
binding Binding No
propertyToSubscribe string No
bindingExpression BindingExpression No
Returns : void
Public clearValue
clearValue(property: DependencyProperty)
Inherited from DependencyObject

Clears the dependency property value

Parameters :
Name Type Optional
property DependencyProperty No
Returns : void
Equals
Equals(obj: any)
Inherited from DependencyObject

Compares this dependency object agains another object.

Parameters :
Name Type Optional
obj any No
Returns : boolean

{boolean}

GetChild
GetChild(idx: number)
Inherited from DependencyObject

Gets the child element at the index position

Parameters :
Name Type Optional
idx number No
Returns : DependencyObject

{DependencyObject}

GetChildrenCount
GetChildrenCount()
Inherited from DependencyObject

Method o know the amount of children the parent has

Returns : number

{number}

GetHashCode
GetHashCode()
Inherited from DependencyObject

Gets a hash code for this dependency object.

Returns : number

{number}

Public getValue
getValue(property: DependencyProperty)
Inherited from DependencyObject

Gets the value of a dependency property

Parameters :
Name Type Optional
property DependencyProperty No
Returns : any
Private handleErrorsOnContext
handleErrorsOnContext(errorCtxt: INotifyDataErrorInfo, args: DataErrorsChangedEventArgs)
Inherited from DependencyObject

Check and register possible errors in an error context

Parameters :
Name Type Optional
errorCtxt INotifyDataErrorInfo No
args DataErrorsChangedEventArgs No
Returns : void
Public IsPropertySet
IsPropertySet(propertyName: string)
Inherited from DependencyObject

Indicates if the property has been already set.

Parameters :
Name Type Optional
propertyName string No
Returns : any
Private performDataErrorValidationIfRequired
performDataErrorValidationIfRequired(binding: Binding, theBindingContext: any)
Inherited from DependencyObject

Performs validation on model if the model implementes IDataErrorINfo

Parameters :
Name Type Optional
binding Binding No
theBindingContext any No
Returns : void
Private performRemoveValidationIfInValidationError
performRemoveValidationIfInValidationError(binding: Binding)
Inherited from DependencyObject

Performs the remove validation if the InValidationError is true

Parameters :
Name Type Optional
binding Binding No
Returns : void
Public performTargetObjectBindingUpdate
performTargetObjectBindingUpdate(dependencyProperty: DependencyProperty, binding: Binding)
Inherited from DependencyObject

Updates the target object value associated to the binding.

Parameters :
Name Type Optional
dependencyProperty DependencyProperty No
binding Binding No
Returns : void
Private preprocessValue
preprocessValue(property: DependencyProperty, value: any)
Inherited from DependencyObject

Preprocess value to be set to dependency property

Parameters :
Name Type Optional
property DependencyProperty No
value any No
Returns : any
Private recreateSubscriptionsForMultiPropertyBindingPath
recreateSubscriptionsForMultiPropertyBindingPath(currentContext: any, outerContext: any, properties: string[], propertyIndex: number, dependencyProperty: DependencyProperty, bindingExpression: BindingExpression, subscriptionsForCurrentBindingPath: Array<>)
Inherited from DependencyObject
Parameters :
Name Type Optional
currentContext any No
outerContext any No
properties string[] No
propertyIndex number No
dependencyProperty DependencyProperty No
bindingExpression BindingExpression No
subscriptionsForCurrentBindingPath Array<> No
Returns : void
Private registerSetPropertyIfRequired
registerSetPropertyIfRequired(name: string)
Inherited from DependencyObject

Register set property if required

Parameters :
Name Type Optional
name string No
Returns : void
Private removeSubscriptionsForMultiPropertyBindingPath
removeSubscriptionsForMultiPropertyBindingPath(subscriptionsForCurrentBindingPath: [], propertyIndex: number)
Inherited from DependencyObject
Parameters :
Name Type Optional
subscriptionsForCurrentBindingPath [] No
propertyIndex number No
Returns : void
removeValidationMessage
removeValidationMessage(propKey: Binding | string)
Inherited from DependencyObject

Removes a validation message associated to a binding or a property name

Parameters :
Name Type Optional
propKey Binding | string No
Returns : void
SetBinding
SetBinding(dependencyProperty: DependencyProperty, binding: Binding)
Inherited from DependencyObject

Sets a binding to the specified property at runtime

Parameters :
Name Type Optional Description
dependencyProperty DependencyProperty No

property to bind

binding Binding No

binding object

Returns : void
Public setValue
setValue(property: DependencyProperty, value: any)
Inherited from DependencyObject

Sets the value for a dependency property

Parameters :
Name Type Optional
property DependencyProperty No
value any No
Returns : void
Public setValueForScopedRegion
setValueForScopedRegion(property: DependencyProperty, value: any, scopedRegionManager: IRegionManager)
Inherited from DependencyObject

Sets the value for a dependency property. This is a workaround to support Scoped Region Managers. A research is required to find out the way to get the application region Manager when scoped region managers are used (when creating the DelayedRegionBehavior, the correct scoped region manager must be passed as an argument).

Parameters :
Name Type Optional
property DependencyProperty No
value any No
scopedRegionManager IRegionManager No
Returns : void
Protected shouldPreventDefaultSourceUpdate
shouldPreventDefaultSourceUpdate(dependencyProperty: DependencyProperty, binding: BindingExpression)
Inherited from DependencyObject
Parameters :
Name Type Optional
dependencyProperty DependencyProperty No
binding BindingExpression No
Returns : boolean
Private subscribeToBindingPathChanges
subscribeToBindingPathChanges(context: any, binding: Binding, dependencyProperty: DependencyProperty, bindingExpression: BindingExpression)
Inherited from DependencyObject
Parameters :
Name Type Optional
context any No
binding Binding No
dependencyProperty DependencyProperty No
bindingExpression BindingExpression No
Returns : void
Private subscribeToErrorsChangedInModel
subscribeToErrorsChangedInModel(errorCtxt: INotifyDataErrorInfo, propertyToSubscribe: string, bindingExpression: BindingExpression)
Inherited from DependencyObject
Parameters :
Name Type Optional
errorCtxt INotifyDataErrorInfo No
propertyToSubscribe string No
bindingExpression BindingExpression No
Returns : void
Private subscribeToPropertyChanges
subscribeToPropertyChanges(currentContext: any, outerContext: any, properties: string[], propertyIndex: number, dependencyProperty: DependencyProperty, bindingExpression: BindingExpression, subscriptionsForCurrentBindingPath: Array<>)
Inherited from DependencyObject
Parameters :
Name Type Optional
currentContext any No
outerContext any No
properties string[] No
propertyIndex number No
dependencyProperty DependencyProperty No
bindingExpression BindingExpression No
subscriptionsForCurrentBindingPath Array<> No
Returns : void
Private updateSourceOfBinding
updateSourceOfBinding(binding: Binding, outerContext: any, dependencyProperty: DependencyProperty)
Inherited from DependencyObject

Updates the source of a binding

Parameters :
Name Type Optional
binding Binding No
outerContext any No
dependencyProperty DependencyProperty No
Returns : void
import { SubscriptionEvent } from '../utils/SubscriptionEvent';
import { DependencyObject } from '../basecomponentmodel/DependencyObject';
import { PresentationFrameworkCollectionModel } from '../models/controls/ItemsControlModel';
import { PropertyPath } from '../basecomponentmodel/Bindings/PropertyPath';
import { DependencyProperty } from '../basecomponentmodel/DependencyProperty';
import { TimeRange } from '../baseframework/TimeRange';

/**
 * Base class for timeline objets
 *
 * @export
 * @abstract
 * @class TimelineModel
 * @extends {DependencyObject}
 * @wType System.Windows.Media.Animation.Timeline
 */
export abstract class TimelineModel extends DependencyObject {
  /**
   *  Start time
   *
   * @type {TimeRange}
   * @memberof TimelineModel
   */
  BeginTime: TimeRange;

  /**
   * Creates an instance of TimelineModel.
   *
   * @memberof TimelineModel
   */
  constructor() {
    super();
    this.Completed = new SubscriptionEvent<any>();
  }

  /**
   * Executes the animation frames
   *
   * @abstract
   * @memberof TimelineModel
   * @wIgnore
   */
  Execute(): void {
    // Not required implementation for abstract class.
  }

  /**
   * Event to be triggered when the storyboard completes
   *
   * @type {SubscriptionEvent<any>}
   * @memberof TimelineModel
   */
  public Completed: SubscriptionEvent<any>;
}

/**
 * Storyboard compatibility class
 *
 * @export
 * @class Storyboard
 * @extends {DependencyObject}
 * @wType System.Windows.Media.Animation.Storyboard
 */
export class Storyboard extends TimelineModel {
  /**
   *  Property information for the `Target` property
   *
   * @static
   * @memberof Storyboard
   * @wIgnore
   */
  public static readonly TargetProperty = new DependencyProperty(
    'Target',
    null,
    null
  );

  /**
   * Property information for the `TargetProperty` property
   *
   * @static
   * @memberof Storyboard
   */
  public static readonly TargetPropertyProperty = new DependencyProperty(
    'TargetProperty',
    null,
    null
  );

  /**
   *  Storyboard name
   *
   * @type {string}
   * @memberof Storyboard
   * @wIgnore
   */
  public Name: string = null;

  /**
   *  Begin time
   *
   * @type {TimeRange}
   * @memberof Storyboard
   * @wIgnore
   */
  public BeginTime: TimeRange = new TimeRange();

  /**
   *  Children of this storyboard
   *
   * @type {PresentationFrameworkCollectionModel<TimelineModel>}
   * @memberof Storyboard
   */
  public readonly Children: PresentationFrameworkCollectionModel<TimelineModel> =
    new TimelineCollection();

  /**
   *  current request for animation
   *
   * @private
   * @type {number}
   * @memberof Storyboard
   */
  private animationId: any = null;

  /**
   * Creates an instance of Storyboard.
   *
   * @memberof Storyboard
   */
  constructor() {
    super();
  }

  /**
   *  Gets the value of the `Target` property
   *
   * @static
   * @param {TimelineModel} obj
   * @return {*}  {*}
   * @memberof Storyboard
   * @wIgnore
   */
  static GetTarget(obj: TimelineModel): any {
    return obj.getValue(Storyboard.TargetProperty);
  }

  /**
   *  Sets the value of the `Target` property
   *
   * @static
   * @param {TimelineModel} obj
   * @param {*} target
   * @memberof Storyboard
   */
  public static SetTarget(obj: TimelineModel, target: any) {
    obj.setValue(Storyboard.TargetProperty, target);
  }

  /**
   *  Gets the value of the `TargetProperty` property
   *
   * @static
   * @param {TimelineModel} obj
   * @return {*}  {PropertyPath}
   * @memberof Storyboard
   */
  static GetTargetProperty(obj: TimelineModel): PropertyPath {
    return obj.getValue(Storyboard.TargetPropertyProperty);
  }

  /**
   *  Sets the value of the `TargetProperty` property
   *
   * @static
   * @param {*} obj
   * @param {PropertyPath} targetProperty
   * @memberof Storyboard
   */
  public static SetTargetProperty(obj: any, targetProperty: PropertyPath) {
    obj.setValue(Storyboard.TargetPropertyProperty, targetProperty);
  }

  /**
   * Starts the animation logic
   *
   * @memberof Storyboard
   */
  public Begin() {
    this.animationId = setTimeout(() => {
      for (const obj of this.Children) {
        obj.Execute();
      }
      this.Completed.fire(null);
      this.animationId = null;
      clearTimeout(this.animationId);
    });
  }

  /**
   *  Stops the current animation
   *
   * @memberof Storyboard
   */
  public Stop() {
    if (this.animationId !== null) {
      clearTimeout(this.animationId);
      this.animationId = null;
    }
  }

  /**
   * Sets the name of the current storyboard object
   *
   * @param {string} name
   * @return {*}  {Storyboard}
   * @memberof Storyboard
   */
  public withName(name: string): Storyboard {
    this.Name = name;
    return this;
  }
}

/**
 *  Collection of timeline objects
 *
 * @export
 * @class TimelineCollection
 * @extends {PresentationFrameworkCollectionModel<TimelineModel>}
 * @wType System.Windows.Media.Animation.TimelineCollection
 */
export class TimelineCollection extends PresentationFrameworkCollectionModel<TimelineModel> {}

/**
 *  Keytime
 *
 * @export
 * @class KeyTime
 * @wType System.Windows.Media.Animation.KeyTime
 */
export class KeyTime {
  /**
   * Time mark
   *
   * @type {TimeRange}
   * @memberof KeyTime
   * @wProperty TimeSpan
   */
  TimeRange: TimeRange;

  /**
   *  Creates an instance of the current `KeyTime` class
   *
   * @static
   * @param {TimeRange} timeRange
   * @return {*}  {KeyTime}
   * @memberof KeyTime
   */
  public static FromTimeSpan(timeRange: TimeRange): KeyTime {
    const result = new KeyTime();
    result.TimeRange = timeRange;
    return result;
  }

  /**
   * Parse a time range string into a `KeyTime`.
   *
   * The format for the input is `dd.hh:mm:ss.ff`, where:
   * - `dd` = days - optional
   * - `hh` = hours - mandatory
   * - `mm` = minutes - optional
   * - `ss` = seconds - optional
   * - `ff` = fractionalSeconds - optional
   *
   * Valid input examples are:
   * - `1.2:3:4.5` = 1 day, 2 hours, 3 minutes, 4 seconds, 500 milliseconds.
   * - `02:30` = 2 hours, 30 minutes.
   * - `3.2:15` = 3 days, 2 hours, 15 minutes.
   * - `13` = *special* - this is interpreted as 13 days, not 13 hours.
   *
   * Invalid input values:
   * - `1.2` = ambiguous input. It could mean 1 day and 2 hours, or 1 second and 200 milliseconds.
   * - `15:52.3` = 15 minutes, 52 seconds and 300 milliseconds. Is invalid because hours is mandatory.
   * - `3:14:` = lacks seconds. In general, a number should always follow `:` or `.`.
   *
   * @static
   * @param {string} input
   * @return {*}  {KeyTime}
   * @memberof KeyTime
   * @wIgnore
   */
  public static Parse(input: string): KeyTime {
    return KeyTime.FromTimeSpan(TimeRange.Parse(input));
  }
}

/**
 *  Keyframe for object values
 *
 * @export
 * @class ObjectKeyFrame
 * @wType System.Windows.Media.Animation.ObjectKeyFrame
 */
export class ObjectKeyFrame {
  /**
   *  Time mark
   *
   * @type {KeyTime}
   * @memberof ObjectKeyFrame
   */
  KeyTime: KeyTime;

  /**
   * Value to set in this keyframe
   *
   * @type {unknown}
   * @memberof ObjectKeyFrame
   */
  Value: unknown;
}

/**
 *  Double value keyframe
 *
 * @export
 * @class DoubleKeyFrame
 * @wType System.Windows.Media.Animation.DoubleKeyFrame
 */
export class DoubleKeyFrame {
  /**
   * Time mark
   *
   * @type {KeyTime}
   * @memberof DoubleKeyFrame
   */
  KeyTime: KeyTime;

  /**
   *  Double value to set
   *
   * @type {number}
   * @memberof DoubleKeyFrame
   */
  Value: number;
}

/**
 *  Double (easing) keyframe
 *
 * @export
 * @class EasingDoubleKeyFrame
 * @extends {DoubleKeyFrame}
 * @wType System.Windows.Media.Animation.EasingDoubleKeyFrame
 */
export class EasingDoubleKeyFrame extends DoubleKeyFrame {}

/**
 *  Keyframe for object properties
 *
 * @export
 * @class DiscreteObjectKeyFrame
 * @extends {ObjectKeyFrame}
 * @wType System.Windows.Media.Animation.DiscreteObjectKeyFrame
 */
export class DiscreteObjectKeyFrame extends ObjectKeyFrame {}

/**
 *  Keyframe collection of object properties
 *
 * @export
 * @class ObjectKeyFrameCollection
 * @extends {PresentationFrameworkCollectionModel<ObjectKeyFrame>}
 * @wType System.Windows.Media.Animation.ObjectKeyFrameCollection
 */
export class ObjectKeyFrameCollection extends PresentationFrameworkCollectionModel<ObjectKeyFrame> {}

/**
 *  Keyframe collection of double property values
 *
 * @export
 * @class DoubleKeyFrameCollection
 * @extends {PresentationFrameworkCollectionModel<DoubleKeyFrame>}
 * @wType System.Windows.Media.Animation.DoubleKeyFrameCollection
 */
export class DoubleKeyFrameCollection extends PresentationFrameworkCollectionModel<DoubleKeyFrame> {}

/**
 *  Animation using object properties and keyframes
 *
 * @export
 * @class ObjectAnimationUsingKeyFrames
 * @extends {TimelineModel}
 * @wType System.Windows.Media.Animation.ObjectAnimationUsingKeyFrames
 */
export class ObjectAnimationUsingKeyFrames extends TimelineModel {
  /**
   *  Collection of keyframes
   *
   * @memberof ObjectAnimationUsingKeyFrames
   */
  KeyFrames = new ObjectKeyFrameCollection();

  /**
   *  Executes the current animation
   *
   * @memberof ObjectAnimationUsingKeyFrames
   * @wIgnore
   */
  Execute() {
    const obj = Storyboard.GetTarget(this);
    const path = Storyboard.GetTargetProperty(this);
    if (path) {
      for (const keyFrame of this.KeyFrames) {
        path.setValueContextObject(obj, keyFrame.Value);
      }
    }
  }
}

/**
 *  Animation of double
 *
 * @export
 * @class DoubleAnimationUsingKeyFrames
 * @wType System.Windows.Media.Animation.DoubleAnimationUsingKeyFrames
 */
export class DoubleAnimationUsingKeyFrames extends TimelineModel {
  /**
   *  Collection of keyframes
   *
   * @memberof DoubleKeyFrameCollection
   */
  KeyFrames = new DoubleKeyFrameCollection();

  /**
   *  Executes the current animation
   *
   * @memberof ObjectAnimationUsingKeyFrames
   * @wIgnore
   */
  Execute() {
    const obj = Storyboard.GetTarget(this);
    const path = Storyboard.GetTargetProperty(this);
    if (path) {
      for (const keyFrame of this.KeyFrames) {
        path.setValueContextObject(obj, keyFrame.Value);
      }
    }
  }
}

/**
 *  Duration object
 *
 * @export
 * @class Duration
 * @wType System.Windows.Duration
 */
export class Duration {
  /**
   * Automatic duration
   *
   * @static
   * @type {Duration}
   * @memberof Duration
   */
  public static Automatic: Duration = new Duration(undefined);

  /**
   * 'Forever' duration
   *
   * @static
   * @type {Duration}
   * @memberof Duration
   */
  public static Forever: Duration = new Duration(undefined);

  /**
   * Duration time
   *
   * @type {TimeRange}
   * @memberof Duration
   */
  public TimeSpan: TimeRange = new TimeRange();

  /**
   *  Verifies if this object has time
   *
   * @readonly
   * @memberof Duration
   */
  public get HasTimeSpan() {
    return typeof this.TimeSpan !== 'undefined';
  }

  /**
   * Creates an instance of Duration.
   * @param {TimeRange} time
   * @memberof Duration
   */
  constructor(time: TimeRange) {
    this.TimeSpan = time;
  }
}

result-matching ""

    No results matching ""