types.ts

  1. import { IArrayFormat } from "@daybrush/utils";
  2. import { SceneItem } from ".";
  3. /**
  4. * @typedef
  5. */
  6. export interface EasingFunction extends Function {
  7. easingName?: string;
  8. }
  9. /**
  10. * @typedef
  11. */
  12. export type FillModeType = "forwards" | "backwards" | "both";
  13. /**
  14. * @typedef
  15. */
  16. export type IterationCountType = number | "infinite";
  17. /**
  18. * @typedef
  19. */
  20. export type EasingType = 0 | EasingFunction;
  21. /**
  22. * @typedef
  23. */
  24. export type DirectionType = "normal" | "reverse" | "alternate" | "alternate-reverse";
  25. /**
  26. * @typedef
  27. */
  28. export type PlayStateType = "paused" | "running";
  29. /**
  30. * @typedef - The Animator options. Properties used in css animation.
  31. * @property - The id represents the unique key of the animator.
  32. * @property - The easing(timing-function) specifies the speed curve of an animation.
  33. * @property - The iterationCount property specifies the number of times an animation should be played.
  34. * @property - The delay property specifies a delay for the start of an animation.
  35. * @property - The fillMode property specifies a style for the element when the animation is not playing (before it starts, after it ends, or both).
  36. * @property - The direction property defines whether an animation should be played forwards, backwards or in alternate cycles.
  37. * @property - The playspeed define the speed at which the play is performed.
  38. * @property - The duration property defines how long an animation should take to complete one cycle.
  39. */
  40. export interface AnimatorOptions {
  41. id: number | string;
  42. easing: string | EasingType;
  43. iterationCount: IterationCountType;
  44. delay: number;
  45. fillMode: FillModeType;
  46. direction: DirectionType;
  47. playSpeed: number;
  48. duration: number;
  49. }
  50. /**
  51. * @typedef
  52. * @extends AnimatorOptions
  53. * @see AnimatorOptions
  54. */
  55. export interface AnimatorState extends AnimatorOptions {
  56. easingName: string;
  57. iterationTime: number;
  58. currentTime: number;
  59. tickTime: number;
  60. iteration: number;
  61. prevTime: number;
  62. playState: PlayStateType;
  63. }
  64. /**
  65. * @typedef
  66. * @extends AnimatorState
  67. * @see AnimatorState
  68. */
  69. export interface SceneState extends AnimatorState {
  70. selector: string | boolean | ((id: number | string) => string);
  71. playCSS: boolean;
  72. exportEvent?: boolean;
  73. }
  74. /**
  75. * @typedef
  76. * @extends AnimatorOptions
  77. * @see AnimatorOptions
  78. */
  79. export interface SceneOptions extends AnimatorOptions {
  80. selector: string | boolean | ((id: number | string) => string);
  81. }
  82. /**
  83. * @typedef
  84. * @extends AnimatorState
  85. * @see AnimatorState
  86. */
  87. export interface SceneItemState extends AnimatorState {
  88. playCSS: boolean;
  89. cssText: string;
  90. selector: string;
  91. exportEvent?: boolean;
  92. }
  93. /**
  94. * @typedef
  95. * @extends AnimatorOptions
  96. * @see AnimatorOptions
  97. */
  98. export interface SceneItemOptions extends AnimatorOptions {
  99. selector: string | boolean | ((id: number | string) => string);
  100. elements: IArrayFormat<AnimateElement> | AnimateElement;
  101. element: IArrayFormat<AnimateElement> | AnimateElement;
  102. target: any;
  103. }
  104. /**
  105. * @typedef
  106. */
  107. export interface PropertyObjectState {
  108. prefix: string;
  109. suffix: string;
  110. model: string;
  111. type: string;
  112. separator: string;
  113. }
  114. /**
  115. * @typedef
  116. */
  117. export type Role = true | RoleObject;
  118. /**
  119. * @typedef
  120. */
  121. export type ElementsType = HTMLElement | HTMLElement[] | NodeListOf<HTMLElement>;
  122. /**
  123. * @typedef
  124. */
  125. export type CallbackType<T = any> = (...args: any[]) => T;
  126. /**
  127. * @typedef
  128. */
  129. export interface EventParameter {
  130. [name: string]: CallbackType | CallbackType[];
  131. }
  132. /**
  133. * @typedef
  134. */
  135. export interface RoleObject {
  136. [role: string]: Role;
  137. }
  138. /**
  139. * @typedef
  140. */
  141. export type NameType = string | number;
  142. /**
  143. * @typedef
  144. */
  145. export type OptionType = ["duration", "fillMode", "direction", "iterationCount", "delay", "easing", "playSpeed"];
  146. /**
  147. * @typedef
  148. */
  149. export type EventType = ["paused", "ended", "timeupdate", "animate", "play", "iteration"];
  150. /**
  151. * @typedef
  152. */
  153. export type AnimateElement = HTMLElement | SVGElement;
  154. /**
  155. * @typedef
  156. */
  157. export interface PlayCondition {
  158. className?: string;
  159. selector?: string | ((item: SceneItem, selector: string) => string);
  160. }