zoomOut.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.ZoomOut = void 0;
  4. const utils_1 = require("./utils");
  5. const ZoomOut = (options) => {
  6. // Small enough to hide or show very small part of mark,
  7. // but bigger enough to not cause bug.
  8. const ZERO = 0.0001;
  9. return (from, to, value, coordinate, defaults) => {
  10. const [shape] = from;
  11. const { transform: prefix = '', fillOpacity = 1, strokeOpacity = 1, opacity = 1, } = shape.style;
  12. const keyframes = [
  13. { transform: `${prefix} scale(1)`.trimStart() },
  14. {
  15. transform: `${prefix} scale(${ZERO})`.trimStart(),
  16. fillOpacity,
  17. strokeOpacity,
  18. opacity,
  19. offset: 0.99,
  20. },
  21. {
  22. transform: `${prefix} scale(${ZERO})`.trimStart(),
  23. fillOpacity: 0,
  24. strokeOpacity: 0,
  25. opacity: 0,
  26. },
  27. ];
  28. const { width, height } = shape.getBoundingClientRect();
  29. // Change transform origin for correct transform.
  30. shape.setOrigin([width / 2, height / 2]);
  31. const animation = shape.animate(keyframes, (0, utils_1.effectTiming)(defaults, value, options));
  32. // Reset transform origin to eliminate side effect for following animations.
  33. animation.finished.then(() => shape.setOrigin(0, 0));
  34. return animation;
  35. };
  36. };
  37. exports.ZoomOut = ZoomOut;
  38. //# sourceMappingURL=zoomOut.js.map