| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.TimingKeyframe = void 0;
- const util_1 = require("@antv/util");
- function range(direction, iterationCount, keyframeCount) {
- const start = 0;
- const end = keyframeCount;
- const normal = [start, end];
- const reverse = [-end + 1, -start + 1];
- if (direction === 'normal')
- return normal;
- if (direction === 'reverse')
- return reverse;
- if (direction === 'alternate') {
- return iterationCount % 2 === 0 ? normal : reverse;
- }
- if (direction === 'reverse-alternate') {
- return iterationCount % 2 === 0 ? reverse : normal;
- }
- }
- /**
- * Set animation options for all descendants.
- */
- function setAnimation(node, duration, easing) {
- const discovered = [node];
- while (discovered.length) {
- const n = discovered.pop();
- n.animate = (0, util_1.deepMix)({
- enter: {
- duration,
- },
- update: {
- duration,
- easing,
- type: 'morphing',
- fill: 'both',
- },
- exit: {
- type: 'fadeOut',
- duration,
- },
- }, n.animate || {});
- const { children } = n;
- if (Array.isArray(children))
- discovered.push(...children);
- }
- return node;
- }
- /**
- * @todo More options, such as fill, totalDuration...
- */
- const TimingKeyframe = () => {
- return (options) => {
- const { children = [], duration = 1000, iterationCount = 1, direction = 'normal', easing = 'ease-in-out-sine', } = options;
- const n = children.length;
- if (!Array.isArray(children) || n === 0)
- return [];
- const { key } = children[0];
- const newChildren = children
- .map((d) => (Object.assign(Object.assign({}, d), { key })))
- .map((d) => setAnimation(d, duration, easing));
- return function* () {
- let count = 0;
- let prevIndex;
- while (iterationCount === 'infinite' || count < iterationCount) {
- const [start, end] = range(direction, count, n);
- for (let i = start; i < end; i += 1) {
- // For reverse direction, the range is from negative to negative
- // so the absolute value of i is the real index for newChildren.
- const index = Math.abs(i);
- // This is for preventing alternate or reverse-alternate keyframe
- // to yield two same node one by one when the direction change.
- if (prevIndex !== index)
- yield newChildren[index];
- prevIndex = index;
- }
- count++;
- }
- };
- };
- };
- exports.TimingKeyframe = TimingKeyframe;
- exports.TimingKeyframe.props = {};
- //# sourceMappingURL=timingKeyframe.js.map
|