testing.mjs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * @license Angular v19.2.4
  3. * (c) 2010-2025 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. import { NoopAnimationPlayer, AUTO_STYLE } from '@angular/animations';
  7. import { ɵvalidateStyleProperty as _validateStyleProperty, ɵcamelCaseToDashCase as _camelCaseToDashCase, ɵvalidateWebAnimatableStyleProperty as _validateWebAnimatableStyleProperty, ɵcontainsElement as _containsElement, ɵgetParentElement as _getParentElement, ɵinvokeQuery as _invokeQuery, ɵnormalizeKeyframes as _normalizeKeyframes, ɵallowPreviousPlayerStylesMerge as _allowPreviousPlayerStylesMerge } from '@angular/animations/browser';
  8. /**
  9. * @publicApi
  10. */
  11. class MockAnimationDriver {
  12. static log = [];
  13. validateStyleProperty(prop) {
  14. return _validateStyleProperty(prop);
  15. }
  16. validateAnimatableStyleProperty(prop) {
  17. const cssProp = _camelCaseToDashCase(prop);
  18. return _validateWebAnimatableStyleProperty(cssProp);
  19. }
  20. containsElement(elm1, elm2) {
  21. return _containsElement(elm1, elm2);
  22. }
  23. getParentElement(element) {
  24. return _getParentElement(element);
  25. }
  26. query(element, selector, multi) {
  27. return _invokeQuery(element, selector, multi);
  28. }
  29. computeStyle(element, prop, defaultValue) {
  30. return defaultValue || '';
  31. }
  32. animate(element, keyframes, duration, delay, easing, previousPlayers = []) {
  33. const player = new MockAnimationPlayer(element, keyframes, duration, delay, easing, previousPlayers);
  34. MockAnimationDriver.log.push(player);
  35. return player;
  36. }
  37. }
  38. /**
  39. * @publicApi
  40. */
  41. class MockAnimationPlayer extends NoopAnimationPlayer {
  42. element;
  43. keyframes;
  44. duration;
  45. delay;
  46. easing;
  47. previousPlayers;
  48. __finished = false;
  49. __started = false;
  50. previousStyles = new Map();
  51. _onInitFns = [];
  52. currentSnapshot = new Map();
  53. _keyframes = [];
  54. constructor(element, keyframes, duration, delay, easing, previousPlayers) {
  55. super(duration, delay);
  56. this.element = element;
  57. this.keyframes = keyframes;
  58. this.duration = duration;
  59. this.delay = delay;
  60. this.easing = easing;
  61. this.previousPlayers = previousPlayers;
  62. this._keyframes = _normalizeKeyframes(keyframes);
  63. if (_allowPreviousPlayerStylesMerge(duration, delay)) {
  64. previousPlayers.forEach((player) => {
  65. if (player instanceof MockAnimationPlayer) {
  66. const styles = player.currentSnapshot;
  67. styles.forEach((val, prop) => this.previousStyles.set(prop, val));
  68. }
  69. });
  70. }
  71. }
  72. /** @internal */
  73. onInit(fn) {
  74. this._onInitFns.push(fn);
  75. }
  76. /** @internal */
  77. init() {
  78. super.init();
  79. this._onInitFns.forEach((fn) => fn());
  80. this._onInitFns = [];
  81. }
  82. reset() {
  83. super.reset();
  84. this.__started = false;
  85. }
  86. finish() {
  87. super.finish();
  88. this.__finished = true;
  89. }
  90. destroy() {
  91. super.destroy();
  92. this.__finished = true;
  93. }
  94. /** @internal */
  95. triggerMicrotask() { }
  96. play() {
  97. super.play();
  98. this.__started = true;
  99. }
  100. hasStarted() {
  101. return this.__started;
  102. }
  103. beforeDestroy() {
  104. const captures = new Map();
  105. this.previousStyles.forEach((val, prop) => captures.set(prop, val));
  106. if (this.hasStarted()) {
  107. // when assembling the captured styles, it's important that
  108. // we build the keyframe styles in the following order:
  109. // {other styles within keyframes, ... previousStyles }
  110. this._keyframes.forEach((kf) => {
  111. for (let [prop, val] of kf) {
  112. if (prop !== 'offset') {
  113. captures.set(prop, this.__finished ? val : AUTO_STYLE);
  114. }
  115. }
  116. });
  117. }
  118. this.currentSnapshot = captures;
  119. }
  120. }
  121. export { MockAnimationDriver, MockAnimationPlayer };
  122. //# sourceMappingURL=testing.mjs.map