testing.mjs 3.8 KB

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