1 | import { __assign, __spreadArrays, __rest, __extends } from 'tslib';
|
2 | import sync, { getFrameData, cancelSync } from 'framesync';
|
3 | import { velocityPerSecond, mix, clamp, distance, progress, linear as linear$1, circOut, interpolate, wrap } from '@popmotion/popcorn';
|
4 | import { invariant, warning } from 'hey-listen';
|
5 | import { number, color, complex, px, percent, degrees, vw, vh, scale, alpha, progressPercentage } from 'style-value-types';
|
6 | import { action, delay, tween, spring, keyframes as keyframes$1, inertia } from 'popmotion';
|
7 | import * as easingLookup from '@popmotion/easing';
|
8 | import { cubicBezier, linear } from '@popmotion/easing';
|
9 | import React__default, { useRef, createContext, useContext, useEffect, createElement, useMemo, forwardRef, Fragment, Component as Component$1, useCallback, useState, cloneElement, Children, isValidElement, useLayoutEffect } from 'react';
|
10 |
|
11 | var isRefObject = function (ref) {
|
12 | return typeof ref === "object" && ref.hasOwnProperty("current");
|
13 | };
|
14 |
|
15 | var isFloat = function (value) {
|
16 | return !isNaN(parseFloat(value));
|
17 | };
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | var MotionValue = (function () {
|
24 | |
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | function MotionValue(init) {
|
33 | var _this = this;
|
34 | |
35 |
|
36 |
|
37 |
|
38 |
|
39 | this.timeDelta = 0;
|
40 | |
41 |
|
42 |
|
43 |
|
44 |
|
45 | this.lastUpdated = 0;
|
46 | |
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 | this.canTrackVelocity = false;
|
54 | this.updateAndNotify = function (v, render) {
|
55 | if (render === void 0) { render = true; }
|
56 | _this.prev = _this.current;
|
57 | _this.current = v;
|
58 | if (_this.updateSubscribers && _this.prev !== _this.current) {
|
59 | _this.updateSubscribers.forEach(_this.notifySubscriber);
|
60 | }
|
61 | if (render && _this.renderSubscribers) {
|
62 | _this.renderSubscribers.forEach(_this.notifySubscriber);
|
63 | }
|
64 |
|
65 | var _a = getFrameData(), delta = _a.delta, timestamp = _a.timestamp;
|
66 | if (_this.lastUpdated !== timestamp) {
|
67 | _this.timeDelta = delta;
|
68 | _this.lastUpdated = timestamp;
|
69 | sync.postRender(_this.scheduleVelocityCheck);
|
70 | }
|
71 | };
|
72 | |
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | this.notifySubscriber = function (subscriber) {
|
83 | subscriber(_this.current);
|
84 | };
|
85 | |
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | this.scheduleVelocityCheck = function () { return sync.postRender(_this.velocityCheck); };
|
94 | |
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 | this.velocityCheck = function (_a) {
|
104 | var timestamp = _a.timestamp;
|
105 | if (timestamp !== _this.lastUpdated) {
|
106 | _this.prev = _this.current;
|
107 | }
|
108 | };
|
109 | this.set(init, false);
|
110 | this.canTrackVelocity = isFloat(this.current);
|
111 | }
|
112 | |
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | MotionValue.prototype.subscribeTo = function (subscriptions, subscription) {
|
119 | var _this = this;
|
120 | var updateSubscriber = function () { return subscription(_this.current); };
|
121 | subscriptions.add(updateSubscriber);
|
122 | return function () { return subscriptions.delete(updateSubscriber); };
|
123 | };
|
124 | |
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 | MotionValue.prototype.onChange = function (subscription) {
|
203 | if (!this.updateSubscribers)
|
204 | this.updateSubscribers = new Set();
|
205 | return this.subscribeTo(this.updateSubscribers, subscription);
|
206 | };
|
207 | MotionValue.prototype.clearListeners = function () {
|
208 | var _a;
|
209 | (_a = this.updateSubscribers) === null || _a === void 0 ? void 0 : _a.clear();
|
210 | };
|
211 | |
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 | MotionValue.prototype.onRenderRequest = function (subscription) {
|
220 | if (!this.renderSubscribers)
|
221 | this.renderSubscribers = new Set();
|
222 |
|
223 | this.notifySubscriber(subscription);
|
224 | return this.subscribeTo(this.renderSubscribers, subscription);
|
225 | };
|
226 | |
227 |
|
228 |
|
229 |
|
230 |
|
231 | MotionValue.prototype.attach = function (passiveEffect) {
|
232 | this.passiveEffect = passiveEffect;
|
233 | };
|
234 | |
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 | MotionValue.prototype.set = function (v, render) {
|
250 | if (render === void 0) { render = true; }
|
251 | if (!render || !this.passiveEffect) {
|
252 | this.updateAndNotify(v, render);
|
253 | }
|
254 | else {
|
255 | this.passiveEffect(v, this.updateAndNotify);
|
256 | }
|
257 | };
|
258 | |
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 | MotionValue.prototype.get = function () {
|
266 | return this.current;
|
267 | };
|
268 | |
269 |
|
270 |
|
271 | MotionValue.prototype.getPrevious = function () {
|
272 | return this.prev;
|
273 | };
|
274 | |
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 | MotionValue.prototype.getVelocity = function () {
|
282 |
|
283 | return this.canTrackVelocity
|
284 | ?
|
285 | velocityPerSecond(parseFloat(this.current) -
|
286 | parseFloat(this.prev), this.timeDelta)
|
287 | : 0;
|
288 | };
|
289 | |
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 | MotionValue.prototype.start = function (animation) {
|
302 | var _this = this;
|
303 | this.stop();
|
304 | return new Promise(function (resolve) {
|
305 | _this.stopAnimation = animation(resolve);
|
306 | }).then(function () { return _this.clearAnimation(); });
|
307 | };
|
308 | |
309 |
|
310 |
|
311 |
|
312 |
|
313 | MotionValue.prototype.stop = function () {
|
314 | if (this.stopAnimation)
|
315 | this.stopAnimation();
|
316 | this.clearAnimation();
|
317 | };
|
318 | |
319 |
|
320 |
|
321 |
|
322 |
|
323 | MotionValue.prototype.isAnimating = function () {
|
324 | return !!this.stopAnimation;
|
325 | };
|
326 | MotionValue.prototype.clearAnimation = function () {
|
327 | this.stopAnimation = null;
|
328 | };
|
329 | |
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 | MotionValue.prototype.destroy = function () {
|
339 | this.updateSubscribers && this.updateSubscribers.clear();
|
340 | this.renderSubscribers && this.renderSubscribers.clear();
|
341 | this.stop();
|
342 | };
|
343 | return MotionValue;
|
344 | }());
|
345 |
|
346 |
|
347 |
|
348 | function motionValue(init) {
|
349 | return new MotionValue(init);
|
350 | }
|
351 |
|
352 |
|
353 |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 | var VisualElement = (function () {
|
361 | function VisualElement(parent, ref) {
|
362 | var _this = this;
|
363 |
|
364 | this.children = new Set();
|
365 |
|
366 | this.latest = {};
|
367 |
|
368 | this.values = new Map();
|
369 |
|
370 | this.valueSubscriptions = new Map();
|
371 |
|
372 | this.config = {};
|
373 |
|
374 |
|
375 | this.update = function () { return _this.config.onUpdate(_this.latest); };
|
376 |
|
377 | this.triggerRender = function () { return _this.render(); };
|
378 | this.scheduleRender = function () { return sync.render(_this.triggerRender, false, true); };
|
379 |
|
380 |
|
381 | this.ref = function (element) {
|
382 | element ? _this.mount(element) : _this.unmount();
|
383 | if (!_this.externalRef)
|
384 | return;
|
385 | if (typeof _this.externalRef === "function") {
|
386 | _this.externalRef(element);
|
387 | }
|
388 | else if (isRefObject(_this.externalRef)) {
|
389 | _this.externalRef.current = element;
|
390 | }
|
391 | };
|
392 |
|
393 | this.parent = parent;
|
394 | this.rootParent = parent ? parent.rootParent : this;
|
395 | this.treePath = parent ? __spreadArrays(parent.treePath, [parent]) : [];
|
396 |
|
397 | this.depth = parent ? parent.depth + 1 : 0;
|
398 |
|
399 |
|
400 | this.externalRef = ref;
|
401 | }
|
402 | VisualElement.prototype.subscribe = function (child) {
|
403 | var _this = this;
|
404 | this.children.add(child);
|
405 | return function () { return _this.children.delete(child); };
|
406 | };
|
407 |
|
408 | VisualElement.prototype.hasValue = function (key) {
|
409 | return this.values.has(key);
|
410 | };
|
411 |
|
412 | VisualElement.prototype.addValue = function (key, value) {
|
413 | if (this.hasValue(key))
|
414 | this.removeValue(key);
|
415 | this.values.set(key, value);
|
416 | this.latest[key] = value.get();
|
417 | if (this.element)
|
418 | this.subscribeToValue(key, value);
|
419 | };
|
420 |
|
421 | VisualElement.prototype.removeValue = function (key) {
|
422 | var unsubscribe = this.valueSubscriptions.get(key);
|
423 | unsubscribe && unsubscribe();
|
424 | this.values.delete(key);
|
425 | delete this.latest[key];
|
426 | this.valueSubscriptions.delete(key);
|
427 | };
|
428 | VisualElement.prototype.getValue = function (key, defaultValue) {
|
429 | var value = this.values.get(key);
|
430 | if (value === undefined && defaultValue !== undefined) {
|
431 | value = new MotionValue(defaultValue);
|
432 | this.addValue(key, value);
|
433 | }
|
434 | return value;
|
435 | };
|
436 |
|
437 | VisualElement.prototype.forEachValue = function (callback) {
|
438 | this.values.forEach(callback);
|
439 | };
|
440 |
|
441 |
|
442 | VisualElement.prototype.getInstance = function () {
|
443 | return this.element;
|
444 | };
|
445 | VisualElement.prototype.updateConfig = function (config) {
|
446 | if (config === void 0) { config = {}; }
|
447 | this.config = __assign({}, config);
|
448 | };
|
449 |
|
450 | VisualElement.prototype.setSingleStaticValue = function (key, value) {
|
451 | this.latest[key] = value;
|
452 | };
|
453 |
|
454 | VisualElement.prototype.setStaticValues = function (values, value) {
|
455 | if (typeof values === "string") {
|
456 | this.setSingleStaticValue(values, value);
|
457 | }
|
458 | else {
|
459 | for (var key in values) {
|
460 | this.setSingleStaticValue(key, values[key]);
|
461 | }
|
462 | }
|
463 | };
|
464 | VisualElement.prototype.scheduleUpdateLayoutDelta = function () {
|
465 | sync.update(this.rootParent.updateLayoutDelta, false, true);
|
466 | };
|
467 |
|
468 | VisualElement.prototype.subscribeToValue = function (key, value) {
|
469 | var _this = this;
|
470 | var onChange = function (latest) {
|
471 | _this.setSingleStaticValue(key, latest);
|
472 | _this.latest[key] = latest;
|
473 | _this.config.onUpdate && sync.update(_this.update, false, true);
|
474 | };
|
475 | var unsubscribeOnChange = value.onChange(onChange);
|
476 | var unsubscribeOnRender = value.onRenderRequest(this.scheduleRender);
|
477 | this.valueSubscriptions.set(key, function () {
|
478 | unsubscribeOnChange();
|
479 | unsubscribeOnRender();
|
480 | });
|
481 | };
|
482 |
|
483 | VisualElement.prototype.mount = function (element) {
|
484 | var _this = this;
|
485 | invariant(!!element, "No ref found. Ensure components created with motion.custom forward refs using React.forwardRef");
|
486 | if (this.parent) {
|
487 | this.removeFromParent = this.parent.subscribe(this);
|
488 | }
|
489 | |
490 |
|
491 |
|
492 |
|
493 | this.element = this.current = element;
|
494 |
|
495 | this.forEachValue(function (value, key) { return _this.subscribeToValue(key, value); });
|
496 | };
|
497 |
|
498 | VisualElement.prototype.unmount = function () {
|
499 | var _this = this;
|
500 | this.forEachValue(function (_, key) { return _this.removeValue(key); });
|
501 | cancelSync.update(this.update);
|
502 | cancelSync.render(this.render);
|
503 | this.removeFromParent && this.removeFromParent();
|
504 | };
|
505 | return VisualElement;
|
506 | }());
|
507 |
|
508 | function noop(any) {
|
509 | return any;
|
510 | }
|
511 |
|
512 |
|
513 |
|
514 |
|
515 |
|
516 |
|
517 | function convertBoundingBoxToAxisBox(_a) {
|
518 | var top = _a.top, left = _a.left, right = _a.right, bottom = _a.bottom;
|
519 | return {
|
520 | x: { min: left, max: right },
|
521 | y: { min: top, max: bottom },
|
522 | };
|
523 | }
|
524 | function convertAxisBoxToBoundingBox(_a) {
|
525 | var x = _a.x, y = _a.y;
|
526 | return {
|
527 | top: y.min,
|
528 | bottom: y.max,
|
529 | left: x.min,
|
530 | right: x.max,
|
531 | };
|
532 | }
|
533 |
|
534 |
|
535 |
|
536 |
|
537 |
|
538 | function transformBoundingBox(_a, transformPoint) {
|
539 | var top = _a.top, left = _a.left, bottom = _a.bottom, right = _a.right;
|
540 | if (transformPoint === void 0) { transformPoint = noop; }
|
541 | var topLeft = transformPoint({ x: left, y: top });
|
542 | var bottomRight = transformPoint({ x: right, y: bottom });
|
543 | return {
|
544 | top: topLeft.y,
|
545 | left: topLeft.x,
|
546 | bottom: bottomRight.y,
|
547 | right: bottomRight.x,
|
548 | };
|
549 | }
|
550 |
|
551 |
|
552 |
|
553 | function axisBox() {
|
554 | return { x: { min: 0, max: 1 }, y: { min: 0, max: 1 } };
|
555 | }
|
556 | function copyAxisBox(box) {
|
557 | return {
|
558 | x: __assign({}, box.x),
|
559 | y: __assign({}, box.y),
|
560 | };
|
561 | }
|
562 |
|
563 |
|
564 |
|
565 | var zeroDelta = {
|
566 | translate: 0,
|
567 | scale: 1,
|
568 | origin: 0,
|
569 | originPoint: 0,
|
570 | };
|
571 | function delta() {
|
572 | return {
|
573 | x: __assign({}, zeroDelta),
|
574 | y: __assign({}, zeroDelta),
|
575 | };
|
576 | }
|
577 |
|
578 |
|
579 |
|
580 |
|
581 | var auto = {
|
582 | test: function (v) { return v === "auto"; },
|
583 | parse: function (v) { return v; },
|
584 | };
|
585 |
|
586 |
|
587 |
|
588 | var int = __assign(__assign({}, number), { transform: Math.round });
|
589 |
|
590 |
|
591 |
|
592 | var defaultValueTypes = {
|
593 |
|
594 | color: color,
|
595 | backgroundColor: color,
|
596 | outlineColor: color,
|
597 | fill: color,
|
598 | stroke: color,
|
599 |
|
600 | borderColor: color,
|
601 | borderTopColor: color,
|
602 | borderRightColor: color,
|
603 | borderBottomColor: color,
|
604 | borderLeftColor: color,
|
605 | borderWidth: px,
|
606 | borderTopWidth: px,
|
607 | borderRightWidth: px,
|
608 | borderBottomWidth: px,
|
609 | borderLeftWidth: px,
|
610 | borderRadius: px,
|
611 | radius: px,
|
612 | borderTopLeftRadius: px,
|
613 | borderTopRightRadius: px,
|
614 | borderBottomRightRadius: px,
|
615 | borderBottomLeftRadius: px,
|
616 |
|
617 | width: px,
|
618 | maxWidth: px,
|
619 | height: px,
|
620 | maxHeight: px,
|
621 | size: px,
|
622 | top: px,
|
623 | right: px,
|
624 | bottom: px,
|
625 | left: px,
|
626 |
|
627 | padding: px,
|
628 | paddingTop: px,
|
629 | paddingRight: px,
|
630 | paddingBottom: px,
|
631 | paddingLeft: px,
|
632 | margin: px,
|
633 | marginTop: px,
|
634 | marginRight: px,
|
635 | marginBottom: px,
|
636 | marginLeft: px,
|
637 |
|
638 | rotate: degrees,
|
639 | rotateX: degrees,
|
640 | rotateY: degrees,
|
641 | rotateZ: degrees,
|
642 | scale: scale,
|
643 | scaleX: scale,
|
644 | scaleY: scale,
|
645 | scaleZ: scale,
|
646 | skew: degrees,
|
647 | skewX: degrees,
|
648 | skewY: degrees,
|
649 | distance: px,
|
650 | translateX: px,
|
651 | translateY: px,
|
652 | translateZ: px,
|
653 | x: px,
|
654 | y: px,
|
655 | z: px,
|
656 | perspective: px,
|
657 | opacity: alpha,
|
658 | originX: progressPercentage,
|
659 | originY: progressPercentage,
|
660 | originZ: px,
|
661 |
|
662 | zIndex: int,
|
663 |
|
664 | fillOpacity: alpha,
|
665 | strokeOpacity: alpha,
|
666 | numOctaves: int,
|
667 | };
|
668 |
|
669 |
|
670 |
|
671 | var dimensionValueTypes = [number, px, percent, degrees, vw, vh, auto];
|
672 |
|
673 |
|
674 |
|
675 | var testValueType = function (v) { return function (type) { return type.test(v); }; };
|
676 |
|
677 |
|
678 |
|
679 | var findDimensionValueType = function (v) {
|
680 | return dimensionValueTypes.find(testValueType(v));
|
681 | };
|
682 |
|
683 |
|
684 |
|
685 | var valueTypes = __spreadArrays(dimensionValueTypes, [color, complex]);
|
686 |
|
687 |
|
688 |
|
689 | var findValueType = function (v) { return valueTypes.find(testValueType(v)); };
|
690 |
|
691 |
|
692 |
|
693 | var getDefaultValueType = function (key) { return defaultValueTypes[key]; };
|
694 |
|
695 |
|
696 |
|
697 | var getValueAsType = function (value, type) {
|
698 | return type && typeof value === "number"
|
699 | ? type.transform(value)
|
700 | : value;
|
701 | };
|
702 |
|
703 |
|
704 |
|
705 |
|
706 |
|
707 | var axes = ["", "X", "Y", "Z"];
|
708 |
|
709 |
|
710 |
|
711 |
|
712 | var order = ["translate", "scale", "rotate", "skew", "transformPerspective"];
|
713 |
|
714 |
|
715 |
|
716 | var transformProps = ["x", "y", "z"];
|
717 | order.forEach(function (operationKey) {
|
718 | axes.forEach(function (axesKey) { return transformProps.push(operationKey + axesKey); });
|
719 | });
|
720 |
|
721 |
|
722 |
|
723 | function sortTransformProps(a, b) {
|
724 | return transformProps.indexOf(a) - transformProps.indexOf(b);
|
725 | }
|
726 |
|
727 |
|
728 |
|
729 | var transformPropSet = new Set(transformProps);
|
730 | function isTransformProp(key) {
|
731 | return transformPropSet.has(key);
|
732 | }
|
733 |
|
734 |
|
735 |
|
736 | var transformOriginProps = new Set(["originX", "originY", "originZ"]);
|
737 | function isTransformOriginProp(key) {
|
738 | return transformOriginProps.has(key);
|
739 | }
|
740 |
|
741 | var translateAlias = {
|
742 | x: "translateX",
|
743 | y: "translateY",
|
744 | z: "translateZ",
|
745 | };
|
746 |
|
747 |
|
748 |
|
749 |
|
750 |
|
751 |
|
752 | function buildTransform(transform, transformKeys, transformTemplate, transformIsDefault, enableHardwareAcceleration, allowTransformNone) {
|
753 | if (enableHardwareAcceleration === void 0) { enableHardwareAcceleration = true; }
|
754 | if (allowTransformNone === void 0) { allowTransformNone = true; }
|
755 |
|
756 | var transformString = "";
|
757 |
|
758 |
|
759 | var transformHasZ = false;
|
760 |
|
761 | transformKeys.sort(sortTransformProps);
|
762 |
|
763 | var numTransformKeys = transformKeys.length;
|
764 | for (var i = 0; i < numTransformKeys; i++) {
|
765 | var key = transformKeys[i];
|
766 | transformString += (translateAlias[key] || key) + "(" + transform[key] + ") ";
|
767 | if (key === "z")
|
768 | transformHasZ = true;
|
769 | }
|
770 | if (!transformHasZ && enableHardwareAcceleration) {
|
771 | transformString += "translateZ(0)";
|
772 | }
|
773 | else {
|
774 | transformString = transformString.trim();
|
775 | }
|
776 |
|
777 |
|
778 | if (transformTemplate) {
|
779 | transformString = transformTemplate(transform, transformIsDefault ? "" : transformString);
|
780 | }
|
781 | else if (allowTransformNone && transformIsDefault) {
|
782 | transformString = "none";
|
783 | }
|
784 | return transformString;
|
785 | }
|
786 |
|
787 |
|
788 |
|
789 |
|
790 | function isCSSVariable(key) {
|
791 | return key.startsWith("--");
|
792 | }
|
793 |
|
794 | function pixelsToPercent(pixels, axis) {
|
795 | return (pixels / (axis.max - axis.min)) * 100;
|
796 | }
|
797 |
|
798 |
|
799 |
|
800 |
|
801 |
|
802 |
|
803 |
|
804 | function correctBorderRadius(latest, viewportBox) {
|
805 | |
806 |
|
807 |
|
808 |
|
809 | if (typeof latest !== "number")
|
810 | return latest;
|
811 | |
812 |
|
813 |
|
814 |
|
815 | var x = pixelsToPercent(latest, viewportBox.x);
|
816 | var y = pixelsToPercent(latest, viewportBox.y);
|
817 | return x + "% " + y + "%";
|
818 | }
|
819 | function correctBoxShadow(latest, _viewportBox, delta, treeScale) {
|
820 |
|
821 | var shadow = complex.parse(latest);
|
822 | var template = complex.createTransformer(latest);
|
823 |
|
824 | var xScale = delta.x.scale * treeScale.x;
|
825 | var yScale = delta.y.scale * treeScale.y;
|
826 |
|
827 | shadow[1] /= xScale;
|
828 | shadow[2] /= yScale;
|
829 | |
830 |
|
831 |
|
832 |
|
833 |
|
834 |
|
835 | var averageScale = mix(xScale, yScale, 0.5);
|
836 |
|
837 | if (typeof shadow[3] === "number")
|
838 | shadow[3] /= averageScale;
|
839 |
|
840 | if (typeof shadow[4] === "number")
|
841 | shadow[4] /= averageScale;
|
842 | return template(shadow);
|
843 | }
|
844 | var borderCorrectionDefinition = {
|
845 | process: correctBorderRadius,
|
846 | };
|
847 | var valueScaleCorrection = {
|
848 | borderRadius: __assign(__assign({}, borderCorrectionDefinition), { applyTo: [
|
849 | "borderTopLeftRadius",
|
850 | "borderTopRightRadius",
|
851 | "borderBottomLeftRadius",
|
852 | "borderBottomRightRadius",
|
853 | ] }),
|
854 | borderTopLeftRadius: borderCorrectionDefinition,
|
855 | borderTopRightRadius: borderCorrectionDefinition,
|
856 | borderBottomLeftRadius: borderCorrectionDefinition,
|
857 | borderBottomRightRadius: borderCorrectionDefinition,
|
858 | boxShadow: {
|
859 | process: correctBoxShadow,
|
860 | },
|
861 | };
|
862 |
|
863 |
|
864 |
|
865 | function addScaleCorrection(correctors) {
|
866 | for (var key in correctors) {
|
867 | valueScaleCorrection[key] = correctors[key];
|
868 | }
|
869 | }
|
870 |
|
871 | function createDeltaTransform(delta, treeScale) {
|
872 | var x = delta.x.translate / treeScale.x;
|
873 | var y = delta.y.translate / treeScale.y;
|
874 | var scaleX = delta.x.scale;
|
875 | var scaleY = delta.y.scale;
|
876 | return "translate3d(" + x + "px, " + y + "px, 0) scale(" + scaleX + ", " + scaleY + ")";
|
877 | }
|
878 |
|
879 |
|
880 |
|
881 |
|
882 |
|
883 |
|
884 |
|
885 |
|
886 |
|
887 |
|
888 |
|
889 |
|
890 |
|
891 |
|
892 |
|
893 |
|
894 |
|
895 |
|
896 |
|
897 |
|
898 |
|
899 | function buildHTMLStyles(latest, style, vars, transform, transformOrigin, transformKeys, _a, isLayoutProjectionEnabled, delta, deltaFinal, treeScale, targetBox) {
|
900 | var enableHardwareAcceleration = _a.enableHardwareAcceleration, transformTemplate = _a.transformTemplate, allowTransformNone = _a.allowTransformNone;
|
901 |
|
902 |
|
903 |
|
904 | transformKeys.length = 0;
|
905 |
|
906 | var hasTransform = !!isLayoutProjectionEnabled;
|
907 | var hasTransformOrigin = !!isLayoutProjectionEnabled;
|
908 |
|
909 | var transformIsNone = true;
|
910 | |
911 |
|
912 |
|
913 |
|
914 |
|
915 | for (var key in latest) {
|
916 | var value = latest[key];
|
917 |
|
918 | var valueType = getDefaultValueType(key);
|
919 | var valueAsType = getValueAsType(value, valueType);
|
920 | if (isTransformProp(key)) {
|
921 |
|
922 | hasTransform = true;
|
923 | transform[key] = valueAsType;
|
924 | transformKeys.push(key);
|
925 | if (!transformIsNone)
|
926 | continue;
|
927 |
|
928 |
|
929 | var defaultValue = valueType.default !== undefined ? valueType.default : 0;
|
930 | if (value !== defaultValue)
|
931 | transformIsNone = false;
|
932 | }
|
933 | else if (isTransformOriginProp(key)) {
|
934 |
|
935 | transformOrigin[key] = valueAsType;
|
936 | hasTransformOrigin = true;
|
937 | }
|
938 | else if (key !== "transform" || typeof value !== "function") {
|
939 |
|
940 |
|
941 | var bucket = isCSSVariable(key) ? vars : style;
|
942 |
|
943 |
|
944 | if (isLayoutProjectionEnabled && valueScaleCorrection[key]) {
|
945 | var corrected = valueScaleCorrection[key].process(value, targetBox, delta, treeScale);
|
946 | |
947 |
|
948 |
|
949 |
|
950 | var applyTo = valueScaleCorrection[key].applyTo;
|
951 | if (applyTo) {
|
952 | var num = applyTo.length;
|
953 | for (var i = 0; i < num; i++) {
|
954 | bucket[applyTo[i]] = corrected;
|
955 | }
|
956 | }
|
957 | else {
|
958 | bucket[key] = corrected;
|
959 | }
|
960 | }
|
961 | else {
|
962 | bucket[key] = valueAsType;
|
963 | }
|
964 | }
|
965 | }
|
966 |
|
967 | if (hasTransform || transformTemplate) {
|
968 | if (!isLayoutProjectionEnabled) {
|
969 | style.transform = buildTransform(transform, transformKeys, transformTemplate, transformIsNone, enableHardwareAcceleration, allowTransformNone);
|
970 | }
|
971 | else {
|
972 | style.transform = createDeltaTransform(deltaFinal, treeScale);
|
973 | if (transformTemplate)
|
974 | style.transform = transformTemplate(transform, style.transform);
|
975 | }
|
976 | }
|
977 |
|
978 | if (hasTransformOrigin) {
|
979 | var originX = isLayoutProjectionEnabled
|
980 | ? deltaFinal.x.origin * 100 + "%"
|
981 | : transformOrigin.originX || "50%";
|
982 | var originY = isLayoutProjectionEnabled
|
983 | ? deltaFinal.y.origin * 100 + "%"
|
984 | : transformOrigin.originY || "50%";
|
985 | var originZ = transformOrigin.originZ || "0";
|
986 | style.transformOrigin = originX + " " + originY + " " + originZ;
|
987 | }
|
988 | }
|
989 |
|
990 |
|
991 |
|
992 |
|
993 |
|
994 |
|
995 | function resetAxis(axis, originAxis) {
|
996 | axis.min = originAxis.min;
|
997 | axis.max = originAxis.max;
|
998 | }
|
999 |
|
1000 |
|
1001 |
|
1002 |
|
1003 |
|
1004 | function resetBox(box, originBox) {
|
1005 | resetAxis(box.x, originBox.x);
|
1006 | resetAxis(box.y, originBox.y);
|
1007 | }
|
1008 |
|
1009 |
|
1010 |
|
1011 | function scalePoint(point, scale, originPoint) {
|
1012 | var distanceFromOrigin = point - originPoint;
|
1013 | var scaled = scale * distanceFromOrigin;
|
1014 | return originPoint + scaled;
|
1015 | }
|
1016 |
|
1017 |
|
1018 |
|
1019 | function applyPointDelta(point, translate, scale, originPoint, boxScale) {
|
1020 | if (boxScale !== undefined) {
|
1021 | point = scalePoint(point, boxScale, originPoint);
|
1022 | }
|
1023 | return scalePoint(point, scale, originPoint) + translate;
|
1024 | }
|
1025 |
|
1026 |
|
1027 |
|
1028 | function applyAxisDelta(axis, translate, scale, originPoint, boxScale) {
|
1029 | if (translate === void 0) { translate = 0; }
|
1030 | if (scale === void 0) { scale = 1; }
|
1031 | axis.min = applyPointDelta(axis.min, translate, scale, originPoint, boxScale);
|
1032 | axis.max = applyPointDelta(axis.max, translate, scale, originPoint, boxScale);
|
1033 | }
|
1034 |
|
1035 |
|
1036 |
|
1037 | function applyBoxDelta(box, _a) {
|
1038 | var x = _a.x, y = _a.y;
|
1039 | applyAxisDelta(box.x, x.translate, x.scale, x.originPoint);
|
1040 | applyAxisDelta(box.y, y.translate, y.scale, y.originPoint);
|
1041 | }
|
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 |
|
1047 | function applyAxisTransforms(final, axis, transforms, _a) {
|
1048 | var key = _a[0], scaleKey = _a[1], originKey = _a[2];
|
1049 |
|
1050 | final.min = axis.min;
|
1051 | final.max = axis.max;
|
1052 | var originPoint = mix(axis.min, axis.max, transforms[originKey] || 0.5);
|
1053 |
|
1054 | applyAxisDelta(final, transforms[key], transforms[scaleKey], originPoint, transforms.scale);
|
1055 | }
|
1056 |
|
1057 |
|
1058 |
|
1059 | var xKeys = ["x", "scaleX", "originX"];
|
1060 | var yKeys = ["y", "scaleY", "originY"];
|
1061 |
|
1062 |
|
1063 |
|
1064 | function applyBoxTransforms(finalBox, box, transforms) {
|
1065 | applyAxisTransforms(finalBox.x, box.x, transforms, xKeys);
|
1066 | applyAxisTransforms(finalBox.y, box.y, transforms, yKeys);
|
1067 | }
|
1068 |
|
1069 |
|
1070 |
|
1071 | function removePointDelta(point, translate, scale, originPoint, boxScale) {
|
1072 | point -= translate;
|
1073 | point = scalePoint(point, 1 / scale, originPoint);
|
1074 | if (boxScale !== undefined) {
|
1075 | point = scalePoint(point, 1 / boxScale, originPoint);
|
1076 | }
|
1077 | return point;
|
1078 | }
|
1079 |
|
1080 |
|
1081 |
|
1082 | function removeAxisDelta(axis, translate, scale, origin, boxScale) {
|
1083 | if (translate === void 0) { translate = 0; }
|
1084 | if (scale === void 0) { scale = 1; }
|
1085 | if (origin === void 0) { origin = 0.5; }
|
1086 | var originPoint = mix(axis.min, axis.max, origin) - translate;
|
1087 | axis.min = removePointDelta(axis.min, translate, scale, originPoint, boxScale);
|
1088 | axis.max = removePointDelta(axis.max, translate, scale, originPoint, boxScale);
|
1089 | }
|
1090 |
|
1091 |
|
1092 |
|
1093 |
|
1094 | function removeAxisTransforms(axis, transforms, _a) {
|
1095 | var key = _a[0], scaleKey = _a[1], originKey = _a[2];
|
1096 | removeAxisDelta(axis, transforms[key], transforms[scaleKey], transforms[originKey], transforms.scale);
|
1097 | }
|
1098 |
|
1099 |
|
1100 |
|
1101 |
|
1102 | function removeBoxTransforms(box, transforms) {
|
1103 | removeAxisTransforms(box.x, transforms, xKeys);
|
1104 | removeAxisTransforms(box.y, transforms, yKeys);
|
1105 | }
|
1106 |
|
1107 |
|
1108 |
|
1109 |
|
1110 |
|
1111 |
|
1112 | function applyTreeDeltas(box, treePath) {
|
1113 | var treeLength = treePath.length;
|
1114 | for (var i = 0; i < treeLength; i++) {
|
1115 | applyBoxDelta(box, treePath[i].delta);
|
1116 | }
|
1117 | }
|
1118 |
|
1119 | var clampProgress = clamp(0, 1);
|
1120 |
|
1121 |
|
1122 |
|
1123 | function isNear(value, target, maxDistance) {
|
1124 | if (target === void 0) { target = 0; }
|
1125 | if (maxDistance === void 0) { maxDistance = 0.01; }
|
1126 | return distance(value, target) < maxDistance;
|
1127 | }
|
1128 |
|
1129 |
|
1130 |
|
1131 | function calcTranslate(source, target, origin) {
|
1132 | var sourcePoint = mix(source.min, source.max, origin);
|
1133 | var targetPoint = mix(target.min, target.max, origin);
|
1134 | return targetPoint - sourcePoint;
|
1135 | }
|
1136 |
|
1137 |
|
1138 |
|
1139 |
|
1140 | function calcOrigin(source, target) {
|
1141 | var origin = 0.5;
|
1142 | var sourceLength = source.max - source.min;
|
1143 | var targetLength = target.max - target.min;
|
1144 | if (targetLength > sourceLength) {
|
1145 | origin = progress(target.min, target.max - sourceLength, source.min);
|
1146 | }
|
1147 | else if (sourceLength > targetLength) {
|
1148 | origin = progress(source.min, source.max - targetLength, target.min);
|
1149 | }
|
1150 | return clampProgress(origin);
|
1151 | }
|
1152 |
|
1153 |
|
1154 |
|
1155 |
|
1156 |
|
1157 |
|
1158 | function updateAxisDelta(delta, source, target, origin) {
|
1159 | var sourceLength = source.max - source.min;
|
1160 | var targetLength = target.max - target.min;
|
1161 | delta.origin = origin === undefined ? calcOrigin(source, target) : origin;
|
1162 | delta.originPoint = mix(source.min, source.max, delta.origin);
|
1163 | delta.scale = targetLength / sourceLength;
|
1164 | if (isNear(delta.scale, 1, 0.0001))
|
1165 | delta.scale = 1;
|
1166 | delta.translate = calcTranslate(source, target, delta.origin);
|
1167 | if (isNear(delta.translate))
|
1168 | delta.translate = 0;
|
1169 | }
|
1170 |
|
1171 |
|
1172 |
|
1173 |
|
1174 |
|
1175 |
|
1176 | function updateBoxDelta(delta, source, target, origin) {
|
1177 | updateAxisDelta(delta.x, source.x, target.x, origin);
|
1178 | updateAxisDelta(delta.y, source.y, target.y, origin);
|
1179 | }
|
1180 |
|
1181 |
|
1182 |
|
1183 | function updateTreeScale(treeScale, parentTreeScale, parentDelta) {
|
1184 | treeScale.x = parentTreeScale.x * parentDelta.x.scale;
|
1185 | treeScale.y = parentTreeScale.y * parentDelta.y.scale;
|
1186 | }
|
1187 |
|
1188 |
|
1189 | function eachAxis(handler) {
|
1190 | return [handler("x"), handler("y")];
|
1191 | }
|
1192 |
|
1193 | var isKeyframesTarget = function (v) {
|
1194 | return Array.isArray(v);
|
1195 | };
|
1196 |
|
1197 | var underDampedSpring = function () { return ({
|
1198 | type: "spring",
|
1199 | stiffness: 500,
|
1200 | damping: 25,
|
1201 | restDelta: 0.5,
|
1202 | restSpeed: 10,
|
1203 | }); };
|
1204 | var overDampedSpring = function (to) { return ({
|
1205 | type: "spring",
|
1206 | stiffness: 700,
|
1207 | damping: to === 0 ? 100 : 35,
|
1208 | }); };
|
1209 | var linearTween = function () { return ({
|
1210 | ease: "linear",
|
1211 | duration: 0.3,
|
1212 | }); };
|
1213 | var keyframes = function (values) { return ({
|
1214 | type: "keyframes",
|
1215 | duration: 0.8,
|
1216 | values: values,
|
1217 | }); };
|
1218 | var defaultTransitions = {
|
1219 | x: underDampedSpring,
|
1220 | y: underDampedSpring,
|
1221 | z: underDampedSpring,
|
1222 | rotate: underDampedSpring,
|
1223 | rotateX: underDampedSpring,
|
1224 | rotateY: underDampedSpring,
|
1225 | rotateZ: underDampedSpring,
|
1226 | scaleX: overDampedSpring,
|
1227 | scaleY: overDampedSpring,
|
1228 | scale: overDampedSpring,
|
1229 | opacity: linearTween,
|
1230 | backgroundColor: linearTween,
|
1231 | color: linearTween,
|
1232 | default: overDampedSpring,
|
1233 | };
|
1234 | var getDefaultTransition = function (valueKey, to) {
|
1235 | var transitionFactory;
|
1236 | if (isKeyframesTarget(to)) {
|
1237 | transitionFactory = keyframes;
|
1238 | }
|
1239 | else {
|
1240 | transitionFactory =
|
1241 | defaultTransitions[valueKey] || defaultTransitions.default;
|
1242 | }
|
1243 | return __assign({ to: to }, transitionFactory(to));
|
1244 | };
|
1245 |
|
1246 |
|
1247 |
|
1248 |
|
1249 |
|
1250 |
|
1251 |
|
1252 |
|
1253 |
|
1254 |
|
1255 |
|
1256 |
|
1257 |
|
1258 |
|
1259 |
|
1260 |
|
1261 |
|
1262 |
|
1263 | var just = function (_a) {
|
1264 | var to = _a.to, duration = _a.duration;
|
1265 | return action(function (_a) {
|
1266 | var update = _a.update, complete = _a.complete;
|
1267 | update(to);
|
1268 | duration ? delay(duration).start({ complete: complete }) : complete();
|
1269 | });
|
1270 | };
|
1271 |
|
1272 | var easingDefinitionToFunction = function (definition) {
|
1273 | if (Array.isArray(definition)) {
|
1274 |
|
1275 | invariant(definition.length === 4, "Cubic bezier arrays must contain four numerical values.");
|
1276 | var x1 = definition[0], y1 = definition[1], x2 = definition[2], y2 = definition[3];
|
1277 | return cubicBezier(x1, y1, x2, y2);
|
1278 | }
|
1279 | else if (typeof definition === "string") {
|
1280 |
|
1281 | invariant(easingLookup[definition] !== undefined, "Invalid easing type '" + definition + "'");
|
1282 | return easingLookup[definition];
|
1283 | }
|
1284 | return definition;
|
1285 | };
|
1286 | var isEasingArray = function (ease) {
|
1287 | return Array.isArray(ease) && typeof ease[0] !== "number";
|
1288 | };
|
1289 |
|
1290 | var isDurationAnimation = function (v) {
|
1291 | return v.hasOwnProperty("duration") || v.hasOwnProperty("repeatDelay");
|
1292 | };
|
1293 |
|
1294 |
|
1295 |
|
1296 |
|
1297 |
|
1298 |
|
1299 |
|
1300 |
|
1301 |
|
1302 |
|
1303 | var isAnimatable = function (key, value) {
|
1304 |
|
1305 | if (key === "zIndex")
|
1306 | return false;
|
1307 |
|
1308 |
|
1309 |
|
1310 | if (typeof value === "number" || Array.isArray(value))
|
1311 | return true;
|
1312 | if (typeof value === "string" &&
|
1313 | complex.test(value) &&
|
1314 | !value.startsWith("url(")
|
1315 | ) {
|
1316 | return true;
|
1317 | }
|
1318 | return false;
|
1319 | };
|
1320 |
|
1321 |
|
1322 |
|
1323 |
|
1324 |
|
1325 |
|
1326 |
|
1327 | var secondsToMilliseconds = function (seconds) { return seconds * 1000; };
|
1328 |
|
1329 | var transitions = { tween: tween, spring: spring, keyframes: keyframes$1, inertia: inertia, just: just };
|
1330 | var transitionOptionParser = {
|
1331 | tween: function (opts) {
|
1332 | if (opts.ease) {
|
1333 | var ease = isEasingArray(opts.ease) ? opts.ease[0] : opts.ease;
|
1334 | opts.ease = easingDefinitionToFunction(ease);
|
1335 | }
|
1336 | return opts;
|
1337 | },
|
1338 | keyframes: function (_a) {
|
1339 | var from = _a.from, to = _a.to, velocity = _a.velocity, opts = __rest(_a, ["from", "to", "velocity"]);
|
1340 | if (opts.values && opts.values[0] === null) {
|
1341 | var values = __spreadArrays(opts.values);
|
1342 | values[0] = from;
|
1343 | opts.values = values;
|
1344 | }
|
1345 | if (opts.ease) {
|
1346 | opts.easings = isEasingArray(opts.ease)
|
1347 | ? opts.ease.map(easingDefinitionToFunction)
|
1348 | : easingDefinitionToFunction(opts.ease);
|
1349 | }
|
1350 | opts.ease = linear;
|
1351 | return opts;
|
1352 | },
|
1353 | };
|
1354 | var isTransitionDefined = function (_a) {
|
1355 | var when = _a.when, delay = _a.delay, delayChildren = _a.delayChildren, staggerChildren = _a.staggerChildren, staggerDirection = _a.staggerDirection, transition = __rest(_a, ["when", "delay", "delayChildren", "staggerChildren", "staggerDirection"]);
|
1356 | return Object.keys(transition).length;
|
1357 | };
|
1358 | var getTransitionDefinition = function (key, to, transitionDefinition) {
|
1359 | var delay = transitionDefinition ? transitionDefinition.delay : 0;
|
1360 |
|
1361 |
|
1362 |
|
1363 | if (transitionDefinition === undefined ||
|
1364 | !isTransitionDefined(transitionDefinition)) {
|
1365 | return __assign({ delay: delay }, getDefaultTransition(key, to));
|
1366 | }
|
1367 | var valueTransitionDefinition = transitionDefinition[key] ||
|
1368 | transitionDefinition.default ||
|
1369 | transitionDefinition;
|
1370 | if (valueTransitionDefinition.type === false) {
|
1371 | return {
|
1372 | delay: valueTransitionDefinition.hasOwnProperty("delay")
|
1373 | ? valueTransitionDefinition.delay
|
1374 | : delay,
|
1375 | to: isKeyframesTarget(to)
|
1376 | ? to[to.length - 1]
|
1377 | : to,
|
1378 | type: "just",
|
1379 | };
|
1380 | }
|
1381 | else if (isKeyframesTarget(to)) {
|
1382 | return __assign(__assign({ values: to, duration: 0.8, delay: delay, ease: "linear" }, valueTransitionDefinition), {
|
1383 |
|
1384 | type: "keyframes" });
|
1385 | }
|
1386 | else {
|
1387 | return __assign({ type: "tween", to: to,
|
1388 | delay: delay }, valueTransitionDefinition);
|
1389 | }
|
1390 | };
|
1391 | var preprocessOptions = function (type, opts) {
|
1392 | return transitionOptionParser[type]
|
1393 | ? transitionOptionParser[type](opts)
|
1394 | : opts;
|
1395 | };
|
1396 | var getAnimation = function (key, value, target, transition) {
|
1397 | var origin = value.get();
|
1398 | var isOriginAnimatable = isAnimatable(key, origin);
|
1399 | var isTargetAnimatable = isAnimatable(key, target);
|
1400 |
|
1401 |
|
1402 | warning(isOriginAnimatable === isTargetAnimatable, "You are trying to animate " + key + " from \"" + origin + "\" to \"" + target + "\". " + origin + " is not an animatable value - to enable this animation set " + origin + " to a value animatable to " + target + " via the `style` property.");
|
1403 |
|
1404 | var _a = getTransitionDefinition(key, target, transition), _b = _a.type, type = _b === void 0 ? "tween" : _b, transitionDefinition = __rest(_a, ["type"]);
|
1405 |
|
1406 | var actionFactory = isOriginAnimatable && isTargetAnimatable
|
1407 | ? transitions[type]
|
1408 | : just;
|
1409 | var opts = preprocessOptions(type, __assign({ from: origin, velocity: value.getVelocity() }, transitionDefinition));
|
1410 |
|
1411 | if (isDurationAnimation(opts)) {
|
1412 | if (opts.duration) {
|
1413 | opts.duration = secondsToMilliseconds(opts.duration);
|
1414 | }
|
1415 | if (opts.repeatDelay) {
|
1416 | opts.repeatDelay = secondsToMilliseconds(opts.repeatDelay);
|
1417 | }
|
1418 | }
|
1419 | return [actionFactory, opts];
|
1420 | };
|
1421 |
|
1422 |
|
1423 |
|
1424 |
|
1425 |
|
1426 | function startAnimation(key, value, target, _a) {
|
1427 | if (_a === void 0) { _a = {}; }
|
1428 | var _b = _a.delay, delay$1 = _b === void 0 ? 0 : _b, transition = __rest(_a, ["delay"]);
|
1429 | return value.start(function (complete) {
|
1430 | var activeAnimation;
|
1431 | var _a = getAnimation(key, value, target, transition), animationFactory = _a[0], _b = _a[1], valueDelay = _b.delay, options = __rest(_b, ["delay"]);
|
1432 | if (valueDelay !== undefined) {
|
1433 | delay$1 = valueDelay;
|
1434 | }
|
1435 | var animate = function () {
|
1436 | var animation = animationFactory(options);
|
1437 |
|
1438 | activeAnimation = animation.start({
|
1439 | update: function (v) { return value.set(v); },
|
1440 | complete: complete,
|
1441 | });
|
1442 | };
|
1443 |
|
1444 |
|
1445 | if (delay$1) {
|
1446 | activeAnimation = delay(secondsToMilliseconds(delay$1)).start({
|
1447 | complete: animate,
|
1448 | });
|
1449 | }
|
1450 | else {
|
1451 | animate();
|
1452 | }
|
1453 | return function () {
|
1454 | if (activeAnimation)
|
1455 | activeAnimation.stop();
|
1456 | };
|
1457 | });
|
1458 | }
|
1459 |
|
1460 |
|
1461 |
|
1462 |
|
1463 |
|
1464 |
|
1465 |
|
1466 |
|
1467 |
|
1468 |
|
1469 | function getBoundingBox(element, transformPagePoint) {
|
1470 | var box = element.getBoundingClientRect();
|
1471 | return convertBoundingBoxToAxisBox(transformBoundingBox(box, transformPagePoint));
|
1472 | }
|
1473 |
|
1474 |
|
1475 |
|
1476 |
|
1477 | var HTMLVisualElement = (function (_super) {
|
1478 | __extends(HTMLVisualElement, _super);
|
1479 | function HTMLVisualElement() {
|
1480 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
1481 | |
1482 |
|
1483 |
|
1484 | _this.defaultConfig = {
|
1485 | enableHardwareAcceleration: true,
|
1486 | allowTransformNone: true,
|
1487 | };
|
1488 | |
1489 |
|
1490 |
|
1491 |
|
1492 | _this.style = {};
|
1493 | |
1494 |
|
1495 |
|
1496 |
|
1497 |
|
1498 | _this.reactStyle = {};
|
1499 | |
1500 |
|
1501 |
|
1502 |
|
1503 | _this.vars = {};
|
1504 | |
1505 |
|
1506 |
|
1507 |
|
1508 | _this.transform = {};
|
1509 | |
1510 |
|
1511 |
|
1512 |
|
1513 | _this.transformOrigin = {};
|
1514 | |
1515 |
|
1516 |
|
1517 |
|
1518 | _this.transformKeys = [];
|
1519 | _this.config = _this.defaultConfig;
|
1520 | |
1521 |
|
1522 |
|
1523 |
|
1524 |
|
1525 | _this.isLayoutProjectionEnabled = false;
|
1526 | |
1527 |
|
1528 |
|
1529 |
|
1530 | _this.layoutUpdateListeners = new Set();
|
1531 | |
1532 |
|
1533 |
|
1534 |
|
1535 | _this.hasViewportBoxUpdated = false;
|
1536 | |
1537 |
|
1538 |
|
1539 |
|
1540 |
|
1541 |
|
1542 | _this.targetBoxFinal = axisBox();
|
1543 | |
1544 |
|
1545 |
|
1546 |
|
1547 |
|
1548 |
|
1549 |
|
1550 | _this.treeScale = { x: 1, y: 1 };
|
1551 | |
1552 |
|
1553 |
|
1554 |
|
1555 |
|
1556 |
|
1557 |
|
1558 |
|
1559 | _this.delta = delta();
|
1560 | |
1561 |
|
1562 |
|
1563 |
|
1564 |
|
1565 |
|
1566 |
|
1567 | _this.deltaFinal = delta();
|
1568 | |
1569 |
|
1570 |
|
1571 | _this.stopLayoutAxisAnimation = {
|
1572 | x: function () { },
|
1573 | y: function () { },
|
1574 | };
|
1575 | _this.isTargetBoxLocked = false;
|
1576 | |
1577 |
|
1578 |
|
1579 | _this.axisProgress = {
|
1580 | x: motionValue(0),
|
1581 | y: motionValue(0),
|
1582 | };
|
1583 | _this.updateLayoutDelta = function () {
|
1584 | _this.isLayoutProjectionEnabled && _this.box && _this.updateLayoutDeltas();
|
1585 | |
1586 |
|
1587 |
|
1588 |
|
1589 |
|
1590 |
|
1591 | _this.children.forEach(fireUpdateLayoutDelta);
|
1592 | };
|
1593 | return _this;
|
1594 | }
|
1595 | |
1596 |
|
1597 |
|
1598 | HTMLVisualElement.prototype.removeValue = function (key) {
|
1599 | _super.prototype.removeValue.call(this, key);
|
1600 | delete this.vars[key];
|
1601 | delete this.style[key];
|
1602 | };
|
1603 | |
1604 |
|
1605 |
|
1606 |
|
1607 |
|
1608 | HTMLVisualElement.prototype.clean = function () {
|
1609 | this.style = {};
|
1610 | this.vars = {};
|
1611 | this.transform = {};
|
1612 | };
|
1613 | HTMLVisualElement.prototype.updateConfig = function (config) {
|
1614 | if (config === void 0) { config = {}; }
|
1615 | this.config = __assign(__assign({}, this.defaultConfig), config);
|
1616 | };
|
1617 | |
1618 |
|
1619 |
|
1620 | HTMLVisualElement.prototype.read = function (key) {
|
1621 | return this.getComputedStyle()[key] || 0;
|
1622 | };
|
1623 | |
1624 |
|
1625 |
|
1626 |
|
1627 |
|
1628 | HTMLVisualElement.prototype.readNativeValue = function (key) {
|
1629 | if (isTransformProp(key)) {
|
1630 | var defaultValueType = getDefaultValueType(key);
|
1631 | return defaultValueType ? defaultValueType.default || 0 : 0;
|
1632 | }
|
1633 | else {
|
1634 | return this.read(key);
|
1635 | }
|
1636 | };
|
1637 | HTMLVisualElement.prototype.enableLayoutProjection = function () {
|
1638 | this.isLayoutProjectionEnabled = true;
|
1639 | };
|
1640 | HTMLVisualElement.prototype.hide = function () {
|
1641 | if (this.isVisible === false)
|
1642 | return;
|
1643 | this.isVisible = false;
|
1644 | this.scheduleRender();
|
1645 | };
|
1646 | HTMLVisualElement.prototype.show = function () {
|
1647 | if (this.isVisible === true)
|
1648 | return;
|
1649 | this.isVisible = true;
|
1650 | this.scheduleRender();
|
1651 | };
|
1652 | |
1653 |
|
1654 |
|
1655 |
|
1656 | HTMLVisualElement.prototype.onLayoutUpdate = function (callback) {
|
1657 | var _this = this;
|
1658 | this.layoutUpdateListeners.add(callback);
|
1659 | return function () { return _this.layoutUpdateListeners.delete(callback); };
|
1660 | };
|
1661 | |
1662 |
|
1663 |
|
1664 |
|
1665 | HTMLVisualElement.prototype.layoutReady = function (config) {
|
1666 | var _this = this;
|
1667 | this.layoutUpdateListeners.forEach(function (listener) {
|
1668 | listener(_this.box, _this.prevViewportBox || _this.box, config);
|
1669 | });
|
1670 | };
|
1671 | |
1672 |
|
1673 |
|
1674 |
|
1675 | HTMLVisualElement.prototype.getBoundingBox = function () {
|
1676 | var transformPagePoint = this.config.transformPagePoint;
|
1677 | return getBoundingBox(this.element, transformPagePoint);
|
1678 | };
|
1679 | HTMLVisualElement.prototype.getBoundingBoxWithoutTransforms = function () {
|
1680 | var bbox = this.getBoundingBox();
|
1681 | removeBoxTransforms(bbox, this.latest);
|
1682 | return bbox;
|
1683 | };
|
1684 | |
1685 |
|
1686 |
|
1687 | HTMLVisualElement.prototype.getComputedStyle = function () {
|
1688 | return window.getComputedStyle(this.element);
|
1689 | };
|
1690 | |
1691 |
|
1692 |
|
1693 | HTMLVisualElement.prototype.snapshotBoundingBox = function () {
|
1694 | this.prevViewportBox = this.getBoundingBoxWithoutTransforms();
|
1695 | |
1696 |
|
1697 |
|
1698 |
|
1699 | var _a = this.axisProgress, x = _a.x, y = _a.y;
|
1700 | if (!this.isTargetBoxLocked && !x.isAnimating() && !y.isAnimating()) {
|
1701 | this.targetBox = copyAxisBox(this.prevViewportBox);
|
1702 | }
|
1703 | };
|
1704 | HTMLVisualElement.prototype.measureLayout = function () {
|
1705 | this.box = this.getBoundingBox();
|
1706 | this.boxCorrected = copyAxisBox(this.box);
|
1707 | if (!this.targetBox)
|
1708 | this.targetBox = copyAxisBox(this.box);
|
1709 | };
|
1710 | |
1711 |
|
1712 |
|
1713 | HTMLVisualElement.prototype.refreshTargetBox = function () {
|
1714 | this.targetBox = this.getBoundingBoxWithoutTransforms();
|
1715 | };
|
1716 | HTMLVisualElement.prototype.lockTargetBox = function () {
|
1717 | this.isTargetBoxLocked = true;
|
1718 | };
|
1719 | HTMLVisualElement.prototype.unlockTargetBox = function () {
|
1720 | this.stopLayoutAnimation();
|
1721 | this.isTargetBoxLocked = false;
|
1722 | };
|
1723 | |
1724 |
|
1725 |
|
1726 |
|
1727 |
|
1728 |
|
1729 |
|
1730 | HTMLVisualElement.prototype.resetTransform = function () {
|
1731 | var transformTemplate = this.config.transformTemplate;
|
1732 | this.element.style.transform = transformTemplate
|
1733 | ? transformTemplate({}, "")
|
1734 | : "none";
|
1735 |
|
1736 | this.scheduleRender();
|
1737 | };
|
1738 | |
1739 |
|
1740 |
|
1741 | HTMLVisualElement.prototype.setAxisTarget = function (axis, min, max) {
|
1742 | var targetAxis = this.targetBox[axis];
|
1743 | targetAxis.min = min;
|
1744 | targetAxis.max = max;
|
1745 |
|
1746 | this.hasViewportBoxUpdated = true;
|
1747 | this.rootParent.scheduleUpdateLayoutDelta();
|
1748 | };
|
1749 | |
1750 |
|
1751 |
|
1752 | HTMLVisualElement.prototype.startLayoutAxisAnimation = function (axis, transition) {
|
1753 | var _this = this;
|
1754 | var progress = this.axisProgress[axis];
|
1755 | var _a = this.targetBox[axis], min = _a.min, max = _a.max;
|
1756 | var length = max - min;
|
1757 | progress.clearListeners();
|
1758 | progress.set(min);
|
1759 | progress.set(min);
|
1760 | progress.onChange(function (v) { return _this.setAxisTarget(axis, v, v + length); });
|
1761 | return startAnimation(axis, progress, 0, transition);
|
1762 | };
|
1763 | HTMLVisualElement.prototype.stopLayoutAnimation = function () {
|
1764 | var _this = this;
|
1765 | eachAxis(function (axis) { return _this.axisProgress[axis].stop(); });
|
1766 | };
|
1767 | |
1768 |
|
1769 |
|
1770 |
|
1771 | HTMLVisualElement.prototype.updateLayoutDeltas = function () {
|
1772 | var _a, _b;
|
1773 | |
1774 |
|
1775 |
|
1776 |
|
1777 | resetBox(this.boxCorrected, this.box);
|
1778 | |
1779 |
|
1780 |
|
1781 |
|
1782 | if (this.parent) {
|
1783 | updateTreeScale(this.treeScale, this.parent.treeScale, this.parent.delta);
|
1784 | }
|
1785 | |
1786 |
|
1787 |
|
1788 |
|
1789 | applyTreeDeltas(this.boxCorrected, this.treePath);
|
1790 | |
1791 |
|
1792 |
|
1793 |
|
1794 |
|
1795 |
|
1796 |
|
1797 |
|
1798 |
|
1799 | updateBoxDelta(this.delta, this.boxCorrected, this.targetBox);
|
1800 | |
1801 |
|
1802 |
|
1803 | this.hasViewportBoxUpdated && ((_b = (_a = this.config).onViewportBoxUpdate) === null || _b === void 0 ? void 0 : _b.call(_a, this.targetBox, this.delta));
|
1804 | this.hasViewportBoxUpdated = false;
|
1805 | |
1806 |
|
1807 |
|
1808 | var deltaTransform = createDeltaTransform(this.delta, this.treeScale);
|
1809 | deltaTransform !== this.deltaTransform && this.scheduleRender();
|
1810 | this.deltaTransform = deltaTransform;
|
1811 | };
|
1812 | HTMLVisualElement.prototype.updateTransformDeltas = function () {
|
1813 | if (!this.isLayoutProjectionEnabled || !this.box)
|
1814 | return;
|
1815 | |
1816 |
|
1817 |
|
1818 |
|
1819 |
|
1820 | applyBoxTransforms(this.targetBoxFinal, this.targetBox, this.latest);
|
1821 | |
1822 |
|
1823 |
|
1824 |
|
1825 |
|
1826 |
|
1827 | updateBoxDelta(this.deltaFinal, this.boxCorrected, this.targetBoxFinal);
|
1828 | };
|
1829 | |
1830 |
|
1831 |
|
1832 |
|
1833 |
|
1834 | |
1835 |
|
1836 |
|
1837 | HTMLVisualElement.prototype.build = function () {
|
1838 | this.updateTransformDeltas();
|
1839 | if (this.isVisible !== undefined) {
|
1840 | this.style.visibility = this.isVisible ? "visible" : "hidden";
|
1841 | }
|
1842 | buildHTMLStyles(this.latest, this.style, this.vars, this.transform, this.transformOrigin, this.transformKeys, this.config, this.isLayoutProjectionEnabled && !!this.box, this.delta, this.deltaFinal, this.treeScale, this.targetBoxFinal);
|
1843 | };
|
1844 | |
1845 |
|
1846 |
|
1847 | HTMLVisualElement.prototype.render = function () {
|
1848 |
|
1849 | this.build();
|
1850 |
|
1851 |
|
1852 | Object.assign(this.element.style, this.style);
|
1853 |
|
1854 | for (var key in this.vars) {
|
1855 | this.element.style.setProperty(key, this.vars[key]);
|
1856 | }
|
1857 | };
|
1858 | return HTMLVisualElement;
|
1859 | }(VisualElement));
|
1860 |
|
1861 |
|
1862 |
|
1863 |
|
1864 | var fireUpdateLayoutDelta = function (child) {
|
1865 | return child.updateLayoutDelta();
|
1866 | };
|
1867 |
|
1868 |
|
1869 |
|
1870 |
|
1871 |
|
1872 |
|
1873 |
|
1874 |
|
1875 | function useConstant(init) {
|
1876 | var ref = useRef(null);
|
1877 | if (ref.current === null) {
|
1878 | ref.current = init();
|
1879 | }
|
1880 | return ref.current;
|
1881 | }
|
1882 |
|
1883 | function calcOrigin$1(origin, offset, size) {
|
1884 | return typeof origin === "string"
|
1885 | ? origin
|
1886 | : px.transform(offset + size * origin);
|
1887 | }
|
1888 |
|
1889 |
|
1890 |
|
1891 |
|
1892 | function calcSVGTransformOrigin(dimensions, originX, originY) {
|
1893 | var pxOriginX = calcOrigin$1(originX, dimensions.x, dimensions.width);
|
1894 | var pxOriginY = calcOrigin$1(originY, dimensions.y, dimensions.height);
|
1895 | return pxOriginX + " " + pxOriginY;
|
1896 | }
|
1897 |
|
1898 |
|
1899 | var progressToPixels = function (progress, length) {
|
1900 | return px.transform(progress * length);
|
1901 | };
|
1902 | var dashKeys = {
|
1903 | offset: "stroke-dashoffset",
|
1904 | array: "stroke-dasharray",
|
1905 | };
|
1906 | var camelKeys = {
|
1907 | offset: "strokeDashoffset",
|
1908 | array: "strokeDasharray",
|
1909 | };
|
1910 |
|
1911 |
|
1912 |
|
1913 |
|
1914 |
|
1915 |
|
1916 |
|
1917 | function buildSVGPath(attrs, totalLength, length, spacing, offset, useDashCase) {
|
1918 | if (spacing === void 0) { spacing = 1; }
|
1919 | if (offset === void 0) { offset = 0; }
|
1920 | if (useDashCase === void 0) { useDashCase = true; }
|
1921 |
|
1922 |
|
1923 | var keys = useDashCase ? dashKeys : camelKeys;
|
1924 |
|
1925 | attrs[keys.offset] = progressToPixels(-offset, totalLength);
|
1926 |
|
1927 | var pathLength = progressToPixels(length, totalLength);
|
1928 | var pathSpacing = progressToPixels(spacing, totalLength);
|
1929 | attrs[keys.array] = pathLength + " " + pathSpacing;
|
1930 | }
|
1931 |
|
1932 | var unmeasured = { x: 0, y: 0, width: 0, height: 0 };
|
1933 |
|
1934 |
|
1935 |
|
1936 | function buildSVGAttrs(_a, style, vars, attrs, transform, transformOrigin, transformKeys, config, dimensions, totalPathLength, isLayoutProjectionEnabled, delta, deltaFinal, treeScale, targetBox) {
|
1937 | var attrX = _a.attrX, attrY = _a.attrY, originX = _a.originX, originY = _a.originY, pathLength = _a.pathLength, _b = _a.pathSpacing, pathSpacing = _b === void 0 ? 1 : _b, _c = _a.pathOffset, pathOffset = _c === void 0 ? 0 : _c,
|
1938 |
|
1939 | latest = __rest(_a, ["attrX", "attrY", "originX", "originY", "pathLength", "pathSpacing", "pathOffset"]);
|
1940 | |
1941 |
|
1942 |
|
1943 | buildHTMLStyles(latest, attrs, vars, transform, transformOrigin, transformKeys, config, isLayoutProjectionEnabled, delta, deltaFinal, treeScale, targetBox);
|
1944 | |
1945 |
|
1946 |
|
1947 |
|
1948 | if (attrs.transform) {
|
1949 | style.transform = attrs.transform;
|
1950 | delete attrs.transform;
|
1951 | }
|
1952 |
|
1953 | if (originX !== undefined || originY !== undefined || style.transform) {
|
1954 | style.transformOrigin = calcSVGTransformOrigin(dimensions || unmeasured, originX !== undefined ? originX : 0.5, originY !== undefined ? originY : 0.5);
|
1955 | }
|
1956 |
|
1957 | if (attrX !== undefined)
|
1958 | attrs.x = attrX;
|
1959 | if (attrY !== undefined)
|
1960 | attrs.y = attrY;
|
1961 |
|
1962 | if (totalPathLength !== undefined && pathLength !== undefined) {
|
1963 | buildSVGPath(attrs, totalPathLength, pathLength, pathSpacing, pathOffset, false);
|
1964 | }
|
1965 | return attrs;
|
1966 | }
|
1967 |
|
1968 |
|
1969 |
|
1970 |
|
1971 | var camelCaseAttributes = new Set([
|
1972 | "baseFrequency",
|
1973 | "diffuseConstant",
|
1974 | "kernelMatrix",
|
1975 | "kernelUnitLength",
|
1976 | "keySplines",
|
1977 | "keyTimes",
|
1978 | "limitingConeAngle",
|
1979 | "markerHeight",
|
1980 | "markerWidth",
|
1981 | "numOctaves",
|
1982 | "targetX",
|
1983 | "targetY",
|
1984 | "surfaceScale",
|
1985 | "specularConstant",
|
1986 | "specularExponent",
|
1987 | "stdDeviation",
|
1988 | "tableValues",
|
1989 | ]);
|
1990 |
|
1991 | var CAMEL_CASE_PATTERN = /([a-z])([A-Z])/g;
|
1992 | var REPLACE_TEMPLATE = "$1-$2";
|
1993 |
|
1994 |
|
1995 |
|
1996 | var camelToDash = function (str) {
|
1997 | return str.replace(CAMEL_CASE_PATTERN, REPLACE_TEMPLATE).toLowerCase();
|
1998 | };
|
1999 |
|
2000 |
|
2001 |
|
2002 |
|
2003 |
|
2004 | var SVGVisualElement = (function (_super) {
|
2005 | __extends(SVGVisualElement, _super);
|
2006 | function SVGVisualElement() {
|
2007 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
2008 | |
2009 |
|
2010 |
|
2011 |
|
2012 | _this.attrs = {};
|
2013 | |
2014 |
|
2015 |
|
2016 | _this.defaultConfig = {
|
2017 | enableHardwareAcceleration: false,
|
2018 | };
|
2019 | |
2020 |
|
2021 |
|
2022 |
|
2023 | _this.config = _this.defaultConfig;
|
2024 | return _this;
|
2025 | }
|
2026 | |
2027 |
|
2028 |
|
2029 |
|
2030 |
|
2031 | SVGVisualElement.prototype.mount = function (element) {
|
2032 | _super.prototype.mount.call(this, element);
|
2033 | this.measure();
|
2034 | };
|
2035 | |
2036 |
|
2037 |
|
2038 | SVGVisualElement.prototype.measure = function () {
|
2039 | try {
|
2040 | this.dimensions =
|
2041 | typeof this.element.getBBox ===
|
2042 | "function"
|
2043 | ? this.element.getBBox()
|
2044 | : this.element.getBoundingClientRect();
|
2045 | }
|
2046 | catch (e) {
|
2047 |
|
2048 | this.dimensions = { x: 0, y: 0, width: 0, height: 0 };
|
2049 | }
|
2050 | if (isPath(this.element)) {
|
2051 | this.totalPathLength = this.element.getTotalLength();
|
2052 | }
|
2053 | };
|
2054 | |
2055 |
|
2056 |
|
2057 | SVGVisualElement.prototype.clean = function () {
|
2058 | _super.prototype.clean.call(this);
|
2059 | this.attrs = {};
|
2060 | };
|
2061 | |
2062 |
|
2063 |
|
2064 | SVGVisualElement.prototype.read = function (key) {
|
2065 | key = !camelCaseAttributes.has(key) ? camelToDash(key) : key;
|
2066 | return this.element.getAttribute(key);
|
2067 | };
|
2068 | SVGVisualElement.prototype.build = function () {
|
2069 | this.updateTransformDeltas();
|
2070 | buildSVGAttrs(this.latest, this.style, this.vars, this.attrs, this.transform, this.transformOrigin, this.transformKeys, this.config, this.dimensions, this.totalPathLength, this.isLayoutProjectionEnabled && !!this.box, this.delta, this.deltaFinal, this.treeScale, this.targetBoxFinal);
|
2071 | };
|
2072 | SVGVisualElement.prototype.render = function () {
|
2073 |
|
2074 | _super.prototype.render.call(this);
|
2075 |
|
2076 | for (var key in this.attrs) {
|
2077 | this.element.setAttribute(camelToDash(key), this.attrs[key]);
|
2078 | }
|
2079 | };
|
2080 | return SVGVisualElement;
|
2081 | }(HTMLVisualElement));
|
2082 | function isPath(element) {
|
2083 | return element.tagName === "path";
|
2084 | }
|
2085 |
|
2086 |
|
2087 |
|
2088 |
|
2089 |
|
2090 |
|
2091 |
|
2092 | var svgElements = [
|
2093 | "animate",
|
2094 | "circle",
|
2095 | "clipPath",
|
2096 | "defs",
|
2097 | "desc",
|
2098 | "ellipse",
|
2099 | "feBlend",
|
2100 | "feColorMatrix",
|
2101 | "feComponentTransfer",
|
2102 | "feComposite",
|
2103 | "feConvolveMatrix",
|
2104 | "feDiffuseLighting",
|
2105 | "feDisplacementMap",
|
2106 | "feDistantLight",
|
2107 | "feDropShadow",
|
2108 | "feFlood",
|
2109 | "feFuncA",
|
2110 | "feFuncB",
|
2111 | "feFuncG",
|
2112 | "feFuncR",
|
2113 | "feGaussianBlur",
|
2114 | "feImage",
|
2115 | "feMerge",
|
2116 | "feMergeNode",
|
2117 | "feMorphology",
|
2118 | "feOffset",
|
2119 | "fePointLight",
|
2120 | "feSpecularLighting",
|
2121 | "feSpotLight",
|
2122 | "feTile",
|
2123 | "feTurbulence",
|
2124 | "filter",
|
2125 | "foreignObject",
|
2126 | "g",
|
2127 | "image",
|
2128 | "line",
|
2129 | "linearGradient",
|
2130 | "marker",
|
2131 | "mask",
|
2132 | "metadata",
|
2133 | "path",
|
2134 | "pattern",
|
2135 | "polygon",
|
2136 | "polyline",
|
2137 | "radialGradient",
|
2138 | "rect",
|
2139 | "stop",
|
2140 | "svg",
|
2141 | "switch",
|
2142 | "symbol",
|
2143 | "text",
|
2144 | "textPath",
|
2145 | "tspan",
|
2146 | "use",
|
2147 | "view",
|
2148 | ];
|
2149 |
|
2150 | var svgTagNames = new Set(svgElements);
|
2151 |
|
2152 |
|
2153 |
|
2154 |
|
2155 |
|
2156 |
|
2157 | function isSVGComponent(Component) {
|
2158 | return typeof Component === "string" && svgTagNames.has(Component);
|
2159 | }
|
2160 |
|
2161 |
|
2162 |
|
2163 |
|
2164 | var PresenceContext = createContext(null);
|
2165 |
|
2166 |
|
2167 |
|
2168 |
|
2169 |
|
2170 |
|
2171 |
|
2172 |
|
2173 |
|
2174 |
|
2175 |
|
2176 |
|
2177 |
|
2178 |
|
2179 |
|
2180 |
|
2181 |
|
2182 |
|
2183 |
|
2184 |
|
2185 |
|
2186 |
|
2187 |
|
2188 |
|
2189 | function usePresence() {
|
2190 | var context = useContext(PresenceContext);
|
2191 | if (context === null)
|
2192 | return [true, null];
|
2193 | var isPresent = context.isPresent, onExitComplete = context.onExitComplete, register = context.register;
|
2194 |
|
2195 |
|
2196 |
|
2197 | var id = useUniqueId();
|
2198 | useEffect(function () { return register(id); }, []);
|
2199 | var safeToRemove = function () { return onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete(id); };
|
2200 | return !isPresent && onExitComplete ? [false, safeToRemove] : [true];
|
2201 | }
|
2202 |
|
2203 |
|
2204 |
|
2205 | function useIsPresent() {
|
2206 | var context = useContext(PresenceContext);
|
2207 | return context === null ? true : context.isPresent;
|
2208 | }
|
2209 | var counter = 0;
|
2210 | var incrementId = function () { return counter++; };
|
2211 | var useUniqueId = function () { return useConstant(incrementId); };
|
2212 |
|
2213 |
|
2214 |
|
2215 |
|
2216 |
|
2217 | var useDomVisualElement = function (Component, props, parent, isStatic, ref) {
|
2218 | var visualElement = useConstant(function () {
|
2219 | var DOMVisualElement = isSVGComponent(Component)
|
2220 | ? SVGVisualElement
|
2221 | : HTMLVisualElement;
|
2222 | return new DOMVisualElement(parent, ref);
|
2223 | });
|
2224 | visualElement.updateConfig(__assign({ enableHardwareAcceleration: !isStatic }, props));
|
2225 | visualElement.layoutId = props.layoutId;
|
2226 | var isPresent = useIsPresent();
|
2227 | visualElement.isPresent =
|
2228 | props.isPresent !== undefined ? props.isPresent : isPresent;
|
2229 | return visualElement;
|
2230 | };
|
2231 |
|
2232 |
|
2233 |
|
2234 |
|
2235 |
|
2236 |
|
2237 |
|
2238 | var validMotionProps = new Set([
|
2239 | "initial",
|
2240 | "animate",
|
2241 | "exit",
|
2242 | "style",
|
2243 | "variants",
|
2244 | "transition",
|
2245 | "transformTemplate",
|
2246 | "transformValues",
|
2247 | "custom",
|
2248 | "inherit",
|
2249 | "static",
|
2250 | "layout",
|
2251 | "layoutId",
|
2252 | "onLayoutAnimationComplete",
|
2253 | "onViewportBoxUpdate",
|
2254 | "onAnimationStart",
|
2255 | "onAnimationComplete",
|
2256 | "onUpdate",
|
2257 | "onDragStart",
|
2258 | "onDrag",
|
2259 | "onDragEnd",
|
2260 | "onMeasureDragConstraints",
|
2261 | "onDirectionLock",
|
2262 | "onDragTransitionEnd",
|
2263 | "drag",
|
2264 | "dragControls",
|
2265 | "dragListener",
|
2266 | "dragConstraints",
|
2267 | "dragDirectionLock",
|
2268 | "dragElastic",
|
2269 | "dragMomentum",
|
2270 | "dragPropagation",
|
2271 | "dragTransition",
|
2272 | "onPan",
|
2273 | "onPanStart",
|
2274 | "onPanEnd",
|
2275 | "onPanSessionStart",
|
2276 | "onTap",
|
2277 | "onTapStart",
|
2278 | "onTapCancel",
|
2279 | "whileHover",
|
2280 | "whileTap",
|
2281 | "onHoverEnd",
|
2282 | "onHoverStart",
|
2283 | ]);
|
2284 |
|
2285 |
|
2286 |
|
2287 |
|
2288 |
|
2289 |
|
2290 |
|
2291 |
|
2292 | function isValidMotionProp(key) {
|
2293 | return validMotionProps.has(key);
|
2294 | }
|
2295 |
|
2296 | var isPropValid = function (key) { return !isValidMotionProp(key); };
|
2297 |
|
2298 |
|
2299 |
|
2300 |
|
2301 |
|
2302 |
|
2303 |
|
2304 |
|
2305 |
|
2306 |
|
2307 |
|
2308 |
|
2309 |
|
2310 | try {
|
2311 | var emotionIsPropValid_1 = require("@emotion/is-prop-valid").default;
|
2312 | isPropValid = function (key) {
|
2313 |
|
2314 | if (key.startsWith("on")) {
|
2315 | return !isValidMotionProp(key);
|
2316 | }
|
2317 | else {
|
2318 | return emotionIsPropValid_1(key);
|
2319 | }
|
2320 | };
|
2321 | }
|
2322 | catch (_a) {
|
2323 |
|
2324 | }
|
2325 | function filterProps(props) {
|
2326 | var domProps = {};
|
2327 | for (var key in props) {
|
2328 | if (isPropValid(key))
|
2329 | domProps[key] = props[key];
|
2330 | }
|
2331 | return domProps;
|
2332 | }
|
2333 |
|
2334 | function buildHTMLProps(visualElement, _a) {
|
2335 | var drag = _a.drag;
|
2336 |
|
2337 | var htmlProps = {
|
2338 | style: __assign(__assign(__assign({}, visualElement.reactStyle), visualElement.style), visualElement.vars),
|
2339 | };
|
2340 | if (!!drag) {
|
2341 |
|
2342 | htmlProps.style.userSelect = "none";
|
2343 |
|
2344 | htmlProps.draggable = false;
|
2345 | }
|
2346 | return htmlProps;
|
2347 | }
|
2348 |
|
2349 |
|
2350 |
|
2351 |
|
2352 | function buildSVGProps(visualElement) {
|
2353 | return __assign(__assign({}, visualElement.attrs), { style: __assign({}, visualElement.reactStyle) });
|
2354 | }
|
2355 |
|
2356 | function render(Component, props, visualElement) {
|
2357 |
|
2358 |
|
2359 | var forwardedProps = typeof Component === "string" ? filterProps(props) : props;
|
2360 | |
2361 |
|
2362 |
|
2363 |
|
2364 |
|
2365 |
|
2366 | visualElement.clean();
|
2367 | visualElement.build();
|
2368 |
|
2369 | var visualProps = isSVGComponent(Component)
|
2370 | ? buildSVGProps(visualElement)
|
2371 | : buildHTMLProps(visualElement, props);
|
2372 | return createElement(Component, __assign(__assign(__assign({}, forwardedProps), { ref: visualElement.ref }), visualProps));
|
2373 | }
|
2374 |
|
2375 | function isCSSVariable$1(value) {
|
2376 | return typeof value === "string" && value.startsWith("var(--");
|
2377 | }
|
2378 |
|
2379 |
|
2380 |
|
2381 |
|
2382 |
|
2383 |
|
2384 |
|
2385 |
|
2386 |
|
2387 | var cssVariableRegex = /var\((--[a-zA-Z0-9-_]+),? ?([a-zA-Z0-9 ()%#.,-]+)?\)/;
|
2388 | function parseCSSVariable(current) {
|
2389 | var match = cssVariableRegex.exec(current);
|
2390 | if (!match)
|
2391 | return [,];
|
2392 | var token = match[1], fallback = match[2];
|
2393 | return [token, fallback];
|
2394 | }
|
2395 | var maxDepth = 4;
|
2396 | function getVariableValue(current, element, depth) {
|
2397 | if (depth === void 0) { depth = 1; }
|
2398 | invariant(depth <= maxDepth, "Max CSS variable fallback depth detected in property \"" + current + "\". This may indicate a circular fallback dependency.");
|
2399 | var _a = parseCSSVariable(current), token = _a[0], fallback = _a[1];
|
2400 |
|
2401 | if (!token)
|
2402 | return;
|
2403 |
|
2404 | var resolved = window.getComputedStyle(element).getPropertyValue(token);
|
2405 | if (resolved) {
|
2406 | return resolved;
|
2407 | }
|
2408 | else if (isCSSVariable$1(fallback)) {
|
2409 |
|
2410 | return getVariableValue(fallback, element, depth + 1);
|
2411 | }
|
2412 | else {
|
2413 | return fallback;
|
2414 | }
|
2415 | }
|
2416 |
|
2417 |
|
2418 |
|
2419 |
|
2420 |
|
2421 | function resolveCSSVariables(visualElement, _a, transitionEnd) {
|
2422 | var target = __rest(_a, []);
|
2423 | var element = visualElement.getInstance();
|
2424 | if (!(element instanceof HTMLElement))
|
2425 | return { target: target, transitionEnd: transitionEnd };
|
2426 |
|
2427 |
|
2428 | if (transitionEnd) {
|
2429 | transitionEnd = __assign({}, transitionEnd);
|
2430 | }
|
2431 |
|
2432 | visualElement.forEachValue(function (value) {
|
2433 | var current = value.get();
|
2434 | if (!isCSSVariable$1(current))
|
2435 | return;
|
2436 | var resolved = getVariableValue(current, element);
|
2437 | if (resolved)
|
2438 | value.set(resolved);
|
2439 | });
|
2440 |
|
2441 |
|
2442 | for (var key in target) {
|
2443 | var current = target[key];
|
2444 | if (!isCSSVariable$1(current))
|
2445 | continue;
|
2446 | var resolved = getVariableValue(current, element);
|
2447 | if (!resolved)
|
2448 | continue;
|
2449 |
|
2450 | target[key] = resolved;
|
2451 |
|
2452 |
|
2453 |
|
2454 | if (transitionEnd && transitionEnd[key] === undefined) {
|
2455 | transitionEnd[key] = current;
|
2456 | }
|
2457 | }
|
2458 | return { target: target, transitionEnd: transitionEnd };
|
2459 | }
|
2460 |
|
2461 | var positionalKeys = new Set([
|
2462 | "width",
|
2463 | "height",
|
2464 | "top",
|
2465 | "left",
|
2466 | "right",
|
2467 | "bottom",
|
2468 | "x",
|
2469 | "y",
|
2470 | ]);
|
2471 | var isPositionalKey = function (key) { return positionalKeys.has(key); };
|
2472 | var hasPositionalKey = function (target) {
|
2473 | return Object.keys(target).some(isPositionalKey);
|
2474 | };
|
2475 | var setAndResetVelocity = function (value, to) {
|
2476 |
|
2477 |
|
2478 | value.set(to, false);
|
2479 | value.set(to);
|
2480 | };
|
2481 | var isNumOrPxType = function (v) {
|
2482 | return v === number || v === px;
|
2483 | };
|
2484 | var BoundingBoxDimension;
|
2485 | (function (BoundingBoxDimension) {
|
2486 | BoundingBoxDimension["width"] = "width";
|
2487 | BoundingBoxDimension["height"] = "height";
|
2488 | BoundingBoxDimension["left"] = "left";
|
2489 | BoundingBoxDimension["right"] = "right";
|
2490 | BoundingBoxDimension["top"] = "top";
|
2491 | BoundingBoxDimension["bottom"] = "bottom";
|
2492 | })(BoundingBoxDimension || (BoundingBoxDimension = {}));
|
2493 | var getPosFromMatrix = function (matrix, pos) {
|
2494 | return parseFloat(matrix.split(", ")[pos]);
|
2495 | };
|
2496 | var getTranslateFromMatrix = function (pos2, pos3) { return function (_bbox, _a) {
|
2497 | var transform = _a.transform;
|
2498 | if (transform === "none" || !transform)
|
2499 | return 0;
|
2500 | var matrix3d = transform.match(/^matrix3d\((.+)\)$/);
|
2501 | if (matrix3d) {
|
2502 | return getPosFromMatrix(matrix3d[1], pos3);
|
2503 | }
|
2504 | else {
|
2505 | var matrix = transform.match(/^matrix\((.+)\)$/);
|
2506 | if (matrix) {
|
2507 | return getPosFromMatrix(matrix[1], pos2);
|
2508 | }
|
2509 | else {
|
2510 | return 0;
|
2511 | }
|
2512 | }
|
2513 | }; };
|
2514 | var transformKeys = new Set(["x", "y", "z"]);
|
2515 | var nonTranslationalTransformKeys = transformProps.filter(function (key) { return !transformKeys.has(key); });
|
2516 | function removeNonTranslationalTransform(visualElement) {
|
2517 | var removedTransforms = [];
|
2518 | nonTranslationalTransformKeys.forEach(function (key) {
|
2519 | var value = visualElement.getValue(key);
|
2520 | if (value !== undefined) {
|
2521 | removedTransforms.push([key, value.get()]);
|
2522 | value.set(key.startsWith("scale") ? 1 : 0);
|
2523 | }
|
2524 | });
|
2525 |
|
2526 | if (removedTransforms.length)
|
2527 | visualElement.render();
|
2528 | return removedTransforms;
|
2529 | }
|
2530 | var positionalValues = {
|
2531 |
|
2532 | width: function (_a) {
|
2533 | var x = _a.x;
|
2534 | return x.max - x.min;
|
2535 | },
|
2536 | height: function (_a) {
|
2537 | var y = _a.y;
|
2538 | return y.max - y.min;
|
2539 | },
|
2540 | top: function (_bbox, _a) {
|
2541 | var top = _a.top;
|
2542 | return parseFloat(top);
|
2543 | },
|
2544 | left: function (_bbox, _a) {
|
2545 | var left = _a.left;
|
2546 | return parseFloat(left);
|
2547 | },
|
2548 | bottom: function (_a, _b) {
|
2549 | var y = _a.y;
|
2550 | var top = _b.top;
|
2551 | return parseFloat(top) + (y.max - y.min);
|
2552 | },
|
2553 | right: function (_a, _b) {
|
2554 | var x = _a.x;
|
2555 | var left = _b.left;
|
2556 | return parseFloat(left) + (x.max - x.min);
|
2557 | },
|
2558 |
|
2559 | x: getTranslateFromMatrix(4, 13),
|
2560 | y: getTranslateFromMatrix(5, 14),
|
2561 | };
|
2562 | var convertChangedValueTypes = function (target, visualElement, changedKeys) {
|
2563 | var originBbox = visualElement.getBoundingBox();
|
2564 | var elementComputedStyle = visualElement.getComputedStyle();
|
2565 | var display = elementComputedStyle.display, top = elementComputedStyle.top, left = elementComputedStyle.left, bottom = elementComputedStyle.bottom, right = elementComputedStyle.right, transform = elementComputedStyle.transform;
|
2566 | var originComputedStyle = { top: top, left: left, bottom: bottom, right: right, transform: transform };
|
2567 |
|
2568 |
|
2569 | if (display === "none") {
|
2570 | visualElement.setStaticValues("display", target.display || "block");
|
2571 | }
|
2572 |
|
2573 | visualElement.render();
|
2574 | var targetBbox = visualElement.getBoundingBox();
|
2575 | changedKeys.forEach(function (key) {
|
2576 |
|
2577 |
|
2578 | var value = visualElement.getValue(key);
|
2579 | setAndResetVelocity(value, positionalValues[key](originBbox, originComputedStyle));
|
2580 | target[key] = positionalValues[key](targetBbox, elementComputedStyle);
|
2581 | });
|
2582 | return target;
|
2583 | };
|
2584 | var checkAndConvertChangedValueTypes = function (visualElement, target, origin, transitionEnd) {
|
2585 | if (origin === void 0) { origin = {}; }
|
2586 | if (transitionEnd === void 0) { transitionEnd = {}; }
|
2587 | target = __assign({}, target);
|
2588 | transitionEnd = __assign({}, transitionEnd);
|
2589 | var targetPositionalKeys = Object.keys(target).filter(isPositionalKey);
|
2590 |
|
2591 |
|
2592 | var removedTransformValues = [];
|
2593 | var hasAttemptedToRemoveTransformValues = false;
|
2594 | var changedValueTypeKeys = [];
|
2595 | targetPositionalKeys.forEach(function (key) {
|
2596 | var value = visualElement.getValue(key);
|
2597 | if (!visualElement.hasValue(key))
|
2598 | return;
|
2599 | var from = origin[key];
|
2600 | var to = target[key];
|
2601 | var fromType = findDimensionValueType(from);
|
2602 | var toType;
|
2603 |
|
2604 |
|
2605 |
|
2606 |
|
2607 | if (isKeyframesTarget(to)) {
|
2608 | var numKeyframes = to.length;
|
2609 | for (var i = to[0] === null ? 1 : 0; i < numKeyframes; i++) {
|
2610 | if (!toType) {
|
2611 | toType = findDimensionValueType(to[i]);
|
2612 | invariant(toType === fromType ||
|
2613 | (isNumOrPxType(fromType) && isNumOrPxType(toType)), "Keyframes must be of the same dimension as the current value");
|
2614 | }
|
2615 | else {
|
2616 | invariant(findDimensionValueType(to[i]) === toType, "All keyframes must be of the same type");
|
2617 | }
|
2618 | }
|
2619 | }
|
2620 | else {
|
2621 | toType = findDimensionValueType(to);
|
2622 | }
|
2623 | if (fromType !== toType) {
|
2624 |
|
2625 |
|
2626 | if (isNumOrPxType(fromType) && isNumOrPxType(toType)) {
|
2627 | var current = value.get();
|
2628 | if (typeof current === "string") {
|
2629 | value.set(parseFloat(current));
|
2630 | }
|
2631 | if (typeof to === "string") {
|
2632 | target[key] = parseFloat(to);
|
2633 | }
|
2634 | else if (Array.isArray(to) && toType === px) {
|
2635 | target[key] = to.map(parseFloat);
|
2636 | }
|
2637 | }
|
2638 | else {
|
2639 |
|
2640 |
|
2641 | if (!hasAttemptedToRemoveTransformValues) {
|
2642 | removedTransformValues = removeNonTranslationalTransform(visualElement);
|
2643 | hasAttemptedToRemoveTransformValues = true;
|
2644 | }
|
2645 | changedValueTypeKeys.push(key);
|
2646 | transitionEnd[key] =
|
2647 | transitionEnd[key] !== undefined
|
2648 | ? transitionEnd[key]
|
2649 | : target[key];
|
2650 | setAndResetVelocity(value, to);
|
2651 | }
|
2652 | }
|
2653 | });
|
2654 | if (changedValueTypeKeys.length) {
|
2655 | var convertedTarget = convertChangedValueTypes(target, visualElement, changedValueTypeKeys);
|
2656 |
|
2657 | if (removedTransformValues.length) {
|
2658 | removedTransformValues.forEach(function (_a) {
|
2659 | var key = _a[0], value = _a[1];
|
2660 | visualElement.getValue(key).set(value);
|
2661 | });
|
2662 | }
|
2663 |
|
2664 | visualElement.render();
|
2665 | return { target: convertedTarget, transitionEnd: transitionEnd };
|
2666 | }
|
2667 | else {
|
2668 | return { target: target, transitionEnd: transitionEnd };
|
2669 | }
|
2670 | };
|
2671 |
|
2672 |
|
2673 |
|
2674 |
|
2675 |
|
2676 |
|
2677 |
|
2678 | function unitConversion(visualElement, target, origin, transitionEnd) {
|
2679 | return hasPositionalKey(target)
|
2680 | ? checkAndConvertChangedValueTypes(visualElement, target, origin, transitionEnd)
|
2681 | : { target: target, transitionEnd: transitionEnd };
|
2682 | }
|
2683 |
|
2684 |
|
2685 |
|
2686 |
|
2687 |
|
2688 | var parseDomVariant = function (visualElement, target, origin, transitionEnd) {
|
2689 | var resolved = resolveCSSVariables(visualElement, target, transitionEnd);
|
2690 | target = resolved.target;
|
2691 | transitionEnd = resolved.transitionEnd;
|
2692 | return unitConversion(visualElement, target, origin, transitionEnd);
|
2693 | };
|
2694 |
|
2695 |
|
2696 |
|
2697 |
|
2698 |
|
2699 |
|
2700 |
|
2701 |
|
2702 |
|
2703 |
|
2704 | function useInitialOrEveryRender(callback, isInitialOnly) {
|
2705 | if (isInitialOnly === void 0) { isInitialOnly = false; }
|
2706 | var isInitialRender = useRef(true);
|
2707 | if (!isInitialOnly || (isInitialOnly && isInitialRender.current)) {
|
2708 | callback();
|
2709 | }
|
2710 | isInitialRender.current = false;
|
2711 | }
|
2712 |
|
2713 |
|
2714 |
|
2715 |
|
2716 |
|
2717 |
|
2718 | var AnimationControls = (function () {
|
2719 | function AnimationControls() {
|
2720 | |
2721 |
|
2722 |
|
2723 |
|
2724 |
|
2725 | this.hasMounted = false;
|
2726 | |
2727 |
|
2728 |
|
2729 |
|
2730 |
|
2731 | this.pendingAnimations = [];
|
2732 | |
2733 |
|
2734 |
|
2735 |
|
2736 |
|
2737 | this.componentControls = new Set();
|
2738 | }
|
2739 | |
2740 |
|
2741 |
|
2742 |
|
2743 |
|
2744 |
|
2745 |
|
2746 | AnimationControls.prototype.setVariants = function (variants) {
|
2747 | this.variants = variants;
|
2748 | this.componentControls.forEach(function (controls) {
|
2749 | return controls.setVariants(variants);
|
2750 | });
|
2751 | };
|
2752 | |
2753 |
|
2754 |
|
2755 |
|
2756 |
|
2757 |
|
2758 |
|
2759 | AnimationControls.prototype.setDefaultTransition = function (transition) {
|
2760 | this.defaultTransition = transition;
|
2761 | this.componentControls.forEach(function (controls) {
|
2762 | return controls.setDefaultTransition(transition);
|
2763 | });
|
2764 | };
|
2765 | |
2766 |
|
2767 |
|
2768 |
|
2769 |
|
2770 |
|
2771 |
|
2772 |
|
2773 | AnimationControls.prototype.subscribe = function (controls) {
|
2774 | var _this = this;
|
2775 | this.componentControls.add(controls);
|
2776 | if (this.variants)
|
2777 | controls.setVariants(this.variants);
|
2778 | if (this.defaultTransition)
|
2779 | controls.setDefaultTransition(this.defaultTransition);
|
2780 | return function () { return _this.componentControls.delete(controls); };
|
2781 | };
|
2782 | |
2783 |
|
2784 |
|
2785 |
|
2786 |
|
2787 |
|
2788 |
|
2789 |
|
2790 |
|
2791 |
|
2792 |
|
2793 |
|
2794 |
|
2795 |
|
2796 |
|
2797 |
|
2798 |
|
2799 |
|
2800 |
|
2801 | AnimationControls.prototype.start = function (definition, transitionOverride) {
|
2802 | var _this = this;
|
2803 | if (this.hasMounted) {
|
2804 | var animations_1 = [];
|
2805 | this.componentControls.forEach(function (controls) {
|
2806 | var animation = controls.start(definition, {
|
2807 | transitionOverride: transitionOverride,
|
2808 | });
|
2809 | animations_1.push(animation);
|
2810 | });
|
2811 | return Promise.all(animations_1);
|
2812 | }
|
2813 | else {
|
2814 | return new Promise(function (resolve) {
|
2815 | _this.pendingAnimations.push({
|
2816 | animation: [definition, transitionOverride],
|
2817 | resolve: resolve,
|
2818 | });
|
2819 | });
|
2820 | }
|
2821 | };
|
2822 | |
2823 |
|
2824 |
|
2825 |
|
2826 |
|
2827 |
|
2828 |
|
2829 |
|
2830 |
|
2831 |
|
2832 |
|
2833 |
|
2834 |
|
2835 |
|
2836 |
|
2837 |
|
2838 |
|
2839 |
|
2840 |
|
2841 |
|
2842 | AnimationControls.prototype.set = function (definition) {
|
2843 | invariant(this.hasMounted, "controls.set() should only be called after a component has mounted. Consider calling within a useEffect hook.");
|
2844 | return this.componentControls.forEach(function (controls) {
|
2845 | return controls.apply(definition);
|
2846 | });
|
2847 | };
|
2848 | |
2849 |
|
2850 |
|
2851 |
|
2852 |
|
2853 |
|
2854 |
|
2855 |
|
2856 |
|
2857 | AnimationControls.prototype.stop = function () {
|
2858 | this.componentControls.forEach(function (controls) { return controls.stop(); });
|
2859 | };
|
2860 | |
2861 |
|
2862 |
|
2863 |
|
2864 |
|
2865 | AnimationControls.prototype.mount = function () {
|
2866 | var _this = this;
|
2867 | this.hasMounted = true;
|
2868 | this.pendingAnimations.forEach(function (_a) {
|
2869 | var animation = _a.animation, resolve = _a.resolve;
|
2870 | return _this.start.apply(_this, animation).then(resolve);
|
2871 | });
|
2872 | };
|
2873 | |
2874 |
|
2875 |
|
2876 |
|
2877 |
|
2878 | AnimationControls.prototype.unmount = function () {
|
2879 | this.hasMounted = false;
|
2880 | this.stop();
|
2881 | };
|
2882 | return AnimationControls;
|
2883 | }());
|
2884 |
|
2885 |
|
2886 |
|
2887 | var animationControls = function () { return new AnimationControls(); };
|
2888 |
|
2889 |
|
2890 |
|
2891 |
|
2892 | var MotionContext = createContext({
|
2893 | static: false,
|
2894 | });
|
2895 | var isVariantLabel = function (v) {
|
2896 | return typeof v === "string" || Array.isArray(v);
|
2897 | };
|
2898 | var isAnimationControls = function (v) {
|
2899 | return v instanceof AnimationControls;
|
2900 | };
|
2901 |
|
2902 |
|
2903 |
|
2904 |
|
2905 |
|
2906 | var useMotionContext = function (parentContext, controls, visualElement, isStatic, _a) {
|
2907 | if (isStatic === void 0) { isStatic = false; }
|
2908 | var initial = _a.initial, animate = _a.animate, variants = _a.variants, whileTap = _a.whileTap, whileHover = _a.whileHover, layoutId = _a.layoutId;
|
2909 |
|
2910 | var presenceContext = useContext(PresenceContext);
|
2911 | var presenceId = presenceContext === null || presenceContext === void 0 ? void 0 : presenceContext.id;
|
2912 | visualElement.isPresenceRoot = parentContext.presenceId !== presenceId;
|
2913 |
|
2914 | if ((presenceContext === null || presenceContext === void 0 ? void 0 : presenceContext.initial) !== undefined) {
|
2915 | initial = presenceContext.initial;
|
2916 | }
|
2917 | var initialState;
|
2918 | if (initial === false && !isAnimationControls(animate)) {
|
2919 | initialState = animate;
|
2920 | }
|
2921 | else if (typeof initial !== "boolean") {
|
2922 | initialState = initial;
|
2923 | }
|
2924 |
|
2925 |
|
2926 | var hasMounted = useRef(false);
|
2927 |
|
2928 |
|
2929 |
|
2930 |
|
2931 |
|
2932 | var shouldPropagateControls = variants ||
|
2933 | isVariantLabel(animate) ||
|
2934 | isVariantLabel(whileTap) ||
|
2935 | isVariantLabel(whileHover) ||
|
2936 | isAnimationControls(animate);
|
2937 |
|
2938 | var targetInitial = isVariantLabel(initialState)
|
2939 | ? initialState
|
2940 | : parentContext.initial;
|
2941 |
|
2942 |
|
2943 | var targetAnimate = isVariantLabel(animate)
|
2944 | ? animate
|
2945 | : parentContext.animate;
|
2946 |
|
2947 |
|
2948 | var initialDependency = isStatic ? targetInitial : null;
|
2949 |
|
2950 |
|
2951 |
|
2952 |
|
2953 | var animateDependency = shouldPropagateControls && isVariantLabel(targetAnimate)
|
2954 | ? targetAnimate
|
2955 | : null;
|
2956 |
|
2957 |
|
2958 |
|
2959 | var context = useMemo(function () { return ({
|
2960 | controls: shouldPropagateControls
|
2961 | ? controls
|
2962 | : parentContext.controls,
|
2963 | initial: targetInitial,
|
2964 | animate: targetAnimate,
|
2965 | visualElement: visualElement,
|
2966 | hasMounted: hasMounted,
|
2967 | isReducedMotion: parentContext.isReducedMotion,
|
2968 | presenceId: presenceId,
|
2969 | }); }, [
|
2970 | initialDependency,
|
2971 | animateDependency,
|
2972 | parentContext.isReducedMotion,
|
2973 | animate,
|
2974 | layoutId,
|
2975 | presenceId,
|
2976 | ]);
|
2977 |
|
2978 | context.static = isStatic;
|
2979 |
|
2980 |
|
2981 | useInitialOrEveryRender(function () {
|
2982 | var initialToApply = initialState || parentContext.initial;
|
2983 | initialToApply && controls.apply(initialToApply);
|
2984 | }, !isStatic);
|
2985 | useEffect(function () {
|
2986 | hasMounted.current = true;
|
2987 | }, []);
|
2988 | return context;
|
2989 | };
|
2990 |
|
2991 | var checkShouldInheritVariant = function (_a) {
|
2992 | var animate = _a.animate, variants = _a.variants, _b = _a.inherit, inherit = _b === void 0 ? true : _b;
|
2993 | return (inherit &&
|
2994 | !!variants &&
|
2995 | (!animate || animate instanceof AnimationControls));
|
2996 | };
|
2997 |
|
2998 | var isMotionValue = function (value) {
|
2999 | return value instanceof MotionValue;
|
3000 | };
|
3001 |
|
3002 |
|
3003 |
|
3004 |
|
3005 |
|
3006 | function useMotionValues(visualElement, props) {
|
3007 | var prev = useConstant(empty);
|
3008 | |
3009 |
|
3010 |
|
3011 | for (var key in prev) {
|
3012 | var isTransform = isTransformProp(key) || isTransformOriginProp(key);
|
3013 | var existsAsProp = props[key];
|
3014 | var existsAsStyle = props.style && props.style[key];
|
3015 | var propIsMotionValue = existsAsProp && isMotionValue(props[key]);
|
3016 | var styleIsMotionValue = existsAsStyle && isMotionValue(props.style[key]);
|
3017 | var transformRemoved = isTransform && !existsAsProp && !existsAsStyle;
|
3018 | var motionValueRemoved = !isTransform && !propIsMotionValue && !styleIsMotionValue;
|
3019 | if (transformRemoved || motionValueRemoved) {
|
3020 | visualElement.removeValue(key);
|
3021 | delete prev[key];
|
3022 | }
|
3023 | }
|
3024 | |
3025 |
|
3026 |
|
3027 | addMotionValues(visualElement, prev, props);
|
3028 | if (props.style)
|
3029 | addMotionValues(visualElement, prev, props.style, true);
|
3030 | |
3031 |
|
3032 |
|
3033 |
|
3034 | if (props.transformValues) {
|
3035 | visualElement.reactStyle = props.transformValues(visualElement.reactStyle);
|
3036 | }
|
3037 | }
|
3038 |
|
3039 |
|
3040 |
|
3041 |
|
3042 |
|
3043 | function addMotionValues(visualElement, prev, source, isStyle) {
|
3044 | if (isStyle === void 0) { isStyle = false; }
|
3045 | if (isStyle)
|
3046 | visualElement.reactStyle = {};
|
3047 | for (var key in source) {
|
3048 | var value = source[key];
|
3049 | var foundMotionValue = false;
|
3050 | if (isMotionValue(value)) {
|
3051 |
|
3052 | if (!reservedNames.has(key)) {
|
3053 | visualElement.addValue(key, value);
|
3054 | foundMotionValue = true;
|
3055 | }
|
3056 | }
|
3057 | else if (isTransformProp(key) || isTransformOriginProp(key)) {
|
3058 |
|
3059 |
|
3060 | if (!visualElement.hasValue(key)) {
|
3061 | visualElement.addValue(key, motionValue(value));
|
3062 | }
|
3063 | else if (value !== prev[key]) {
|
3064 |
|
3065 |
|
3066 | var motion = visualElement.getValue(key);
|
3067 | motion.set(value);
|
3068 | }
|
3069 | foundMotionValue = true;
|
3070 | }
|
3071 | else if (isStyle) {
|
3072 | visualElement.reactStyle[key] = value;
|
3073 | }
|
3074 | if (foundMotionValue)
|
3075 | prev[key] = value;
|
3076 | }
|
3077 | }
|
3078 |
|
3079 |
|
3080 |
|
3081 |
|
3082 | var reservedNames = new Set([]);
|
3083 | var empty = function () { return ({}); };
|
3084 |
|
3085 | var isCustomValue = function (v) {
|
3086 | return Boolean(v && typeof v === "object" && v.mix && v.toValue);
|
3087 | };
|
3088 | var resolveFinalValueInKeyframes = function (v) {
|
3089 |
|
3090 | return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
|
3091 | };
|
3092 |
|
3093 |
|
3094 |
|
3095 |
|
3096 | var isNumericalString = function (v) { return /^\-?\d*\.?\d+$/.test(v); };
|
3097 |
|
3098 |
|
3099 |
|
3100 |
|
3101 | var getCurrent = function (visualElement) {
|
3102 | var current = {};
|
3103 | visualElement.forEachValue(function (value, key) { return (current[key] = value.get()); });
|
3104 | return current;
|
3105 | };
|
3106 |
|
3107 |
|
3108 |
|
3109 | var getVelocity = function (visualElement) {
|
3110 | var velocity = {};
|
3111 | visualElement.forEachValue(function (value, key) { return (velocity[key] = value.getVelocity()); });
|
3112 | return velocity;
|
3113 | };
|
3114 |
|
3115 |
|
3116 |
|
3117 |
|
3118 | var isTargetResolver = function (p) {
|
3119 | return typeof p === "function";
|
3120 | };
|
3121 |
|
3122 |
|
3123 |
|
3124 | var isVariantLabels = function (v) { return Array.isArray(v); };
|
3125 |
|
3126 |
|
3127 |
|
3128 |
|
3129 |
|
3130 | var VisualElementAnimationControls = (function () {
|
3131 | function VisualElementAnimationControls(visualElement, _a) {
|
3132 | var _this = this;
|
3133 | var makeTargetAnimatable = _a.makeTargetAnimatable;
|
3134 | |
3135 |
|
3136 |
|
3137 |
|
3138 |
|
3139 | this.props = {};
|
3140 | |
3141 |
|
3142 |
|
3143 | this.variants = {};
|
3144 | |
3145 |
|
3146 |
|
3147 | this.baseTarget = {};
|
3148 | |
3149 |
|
3150 |
|
3151 | this.overrides = [];
|
3152 | |
3153 |
|
3154 |
|
3155 | this.resolvedOverrides = [];
|
3156 | |
3157 |
|
3158 |
|
3159 | this.activeOverrides = new Set();
|
3160 | |
3161 |
|
3162 |
|
3163 | this.isAnimating = new Set();
|
3164 | |
3165 |
|
3166 |
|
3167 |
|
3168 | this.hasValue = function (key) { return !_this.visualElement.hasValue(key); };
|
3169 | this.visualElement = visualElement;
|
3170 | this.makeTargetAnimatable = makeTargetAnimatable;
|
3171 | this.visualElement.forEachValue(function (value, key) { return (_this.baseTarget[key] = value.get()); });
|
3172 | }
|
3173 | |
3174 |
|
3175 |
|
3176 |
|
3177 | VisualElementAnimationControls.prototype.setProps = function (props) {
|
3178 | this.props = props;
|
3179 | };
|
3180 | |
3181 |
|
3182 |
|
3183 |
|
3184 | VisualElementAnimationControls.prototype.setVariants = function (variants) {
|
3185 | if (variants)
|
3186 | this.variants = variants;
|
3187 | };
|
3188 | |
3189 |
|
3190 |
|
3191 |
|
3192 | VisualElementAnimationControls.prototype.setDefaultTransition = function (transition) {
|
3193 | if (transition)
|
3194 | this.defaultTransition = transition;
|
3195 | };
|
3196 | |
3197 |
|
3198 |
|
3199 |
|
3200 |
|
3201 |
|
3202 | VisualElementAnimationControls.prototype.setValues = function (definition, _a) {
|
3203 | var _b = _a === void 0 ? {} : _a, _c = _b.isActive, isActive = _c === void 0 ? new Set() : _c, priority = _b.priority;
|
3204 | var _d = this.resolveVariant(definition), target = _d.target, transitionEnd = _d.transitionEnd;
|
3205 | target = this.transformValues(__assign(__assign({}, target), transitionEnd));
|
3206 | for (var key in target) {
|
3207 | if (isActive.has(key))
|
3208 | return;
|
3209 | isActive.add(key);
|
3210 | if (target) {
|
3211 | var targetValue = resolveFinalValueInKeyframes(target[key]);
|
3212 | if (this.visualElement.hasValue(key)) {
|
3213 | var value = this.visualElement.getValue(key);
|
3214 | value && value.set(targetValue);
|
3215 | }
|
3216 | else {
|
3217 | this.visualElement.addValue(key, motionValue(targetValue));
|
3218 | }
|
3219 | if (!priority)
|
3220 | this.baseTarget[key] = targetValue;
|
3221 | }
|
3222 | }
|
3223 | };
|
3224 | |
3225 |
|
3226 |
|
3227 |
|
3228 |
|
3229 |
|
3230 |
|
3231 |
|
3232 | VisualElementAnimationControls.prototype.transformValues = function (values) {
|
3233 | var transformValues = this.props.transformValues;
|
3234 | return transformValues ? transformValues(values) : values;
|
3235 | };
|
3236 | |
3237 |
|
3238 |
|
3239 |
|
3240 |
|
3241 |
|
3242 |
|
3243 |
|
3244 |
|
3245 |
|
3246 | VisualElementAnimationControls.prototype.checkForNewValues = function (target) {
|
3247 | var newValueKeys = Object.keys(target).filter(this.hasValue);
|
3248 | var numNewValues = newValueKeys.length;
|
3249 | if (!numNewValues)
|
3250 | return;
|
3251 | for (var i = 0; i < numNewValues; i++) {
|
3252 | var key = newValueKeys[i];
|
3253 | var targetValue = target[key];
|
3254 | var value = null;
|
3255 |
|
3256 |
|
3257 | if (Array.isArray(targetValue)) {
|
3258 | value = targetValue[0];
|
3259 | }
|
3260 |
|
3261 |
|
3262 |
|
3263 | if (value === null) {
|
3264 | var readValue = this.visualElement.readNativeValue(key);
|
3265 | value = readValue !== undefined ? readValue : target[key];
|
3266 | invariant(value !== null, "No initial value for \"" + key + "\" can be inferred. Ensure an initial value for \"" + key + "\" is defined on the component.");
|
3267 | }
|
3268 | if (typeof value === "string" && isNumericalString(value)) {
|
3269 |
|
3270 | value = parseFloat(value);
|
3271 | }
|
3272 | else if (!findValueType(value) && complex.test(targetValue)) {
|
3273 |
|
3274 | value = complex.getAnimatableNone(targetValue);
|
3275 | }
|
3276 | this.visualElement.addValue(key, motionValue(value));
|
3277 | this.baseTarget[key] = value;
|
3278 | }
|
3279 | };
|
3280 | |
3281 |
|
3282 |
|
3283 |
|
3284 | VisualElementAnimationControls.prototype.resolveVariant = function (variant) {
|
3285 | if (!variant) {
|
3286 | return {
|
3287 | target: undefined,
|
3288 | transition: undefined,
|
3289 | transitionEnd: undefined,
|
3290 | };
|
3291 | }
|
3292 | if (isTargetResolver(variant)) {
|
3293 |
|
3294 | variant = variant(this.props.custom, getCurrent(this.visualElement), getVelocity(this.visualElement));
|
3295 | }
|
3296 | var _a = variant.transition, transition = _a === void 0 ? this.defaultTransition : _a, transitionEnd = variant.transitionEnd, target = __rest(variant, ["transition", "transitionEnd"]);
|
3297 | return { transition: transition, transitionEnd: transitionEnd, target: target };
|
3298 | };
|
3299 | |
3300 |
|
3301 |
|
3302 | VisualElementAnimationControls.prototype.getHighestPriority = function () {
|
3303 | if (!this.activeOverrides.size)
|
3304 | return 0;
|
3305 | return Math.max.apply(Math, Array.from(this.activeOverrides));
|
3306 | };
|
3307 | |
3308 |
|
3309 |
|
3310 |
|
3311 |
|
3312 |
|
3313 |
|
3314 |
|
3315 |
|
3316 | VisualElementAnimationControls.prototype.setOverride = function (definition, overrideIndex) {
|
3317 | this.overrides[overrideIndex] = definition;
|
3318 | if (this.children) {
|
3319 | this.children.forEach(function (child) {
|
3320 | return child.setOverride(definition, overrideIndex);
|
3321 | });
|
3322 | }
|
3323 | };
|
3324 | |
3325 |
|
3326 |
|
3327 |
|
3328 | VisualElementAnimationControls.prototype.startOverride = function (overrideIndex) {
|
3329 | var override = this.overrides[overrideIndex];
|
3330 | if (override) {
|
3331 | return this.start(override, { priority: overrideIndex });
|
3332 | }
|
3333 | };
|
3334 | |
3335 |
|
3336 |
|
3337 |
|
3338 |
|
3339 | VisualElementAnimationControls.prototype.clearOverride = function (overrideIndex) {
|
3340 | var _this = this;
|
3341 | if (this.children) {
|
3342 | this.children.forEach(function (child) { return child.clearOverride(overrideIndex); });
|
3343 | }
|
3344 | var override = this.overrides[overrideIndex];
|
3345 | if (!override)
|
3346 | return;
|
3347 | this.activeOverrides.delete(overrideIndex);
|
3348 | var highest = this.getHighestPriority();
|
3349 | this.resetIsAnimating();
|
3350 | if (highest) {
|
3351 | var highestOverride = this.overrides[highest];
|
3352 | highestOverride && this.startOverride(highest);
|
3353 | }
|
3354 |
|
3355 | var overrideTarget = this.resolvedOverrides[overrideIndex];
|
3356 | if (!overrideTarget)
|
3357 | return;
|
3358 | var remainingValues = {};
|
3359 | for (var key in this.baseTarget) {
|
3360 | if (overrideTarget[key] !== undefined) {
|
3361 | remainingValues[key] = this.baseTarget[key];
|
3362 | }
|
3363 | }
|
3364 | this.onStart();
|
3365 | this.animate(remainingValues).then(function () { return _this.onComplete(); });
|
3366 | };
|
3367 | |
3368 |
|
3369 |
|
3370 | VisualElementAnimationControls.prototype.apply = function (definition) {
|
3371 | if (Array.isArray(definition)) {
|
3372 | return this.applyVariantLabels(definition);
|
3373 | }
|
3374 | else if (typeof definition === "string") {
|
3375 | return this.applyVariantLabels([definition]);
|
3376 | }
|
3377 | else {
|
3378 | this.setValues(definition);
|
3379 | }
|
3380 | };
|
3381 | |
3382 |
|
3383 |
|
3384 | VisualElementAnimationControls.prototype.applyVariantLabels = function (variantLabelList) {
|
3385 | var _this = this;
|
3386 | var isActive = new Set();
|
3387 | var reversedList = __spreadArrays(variantLabelList).reverse();
|
3388 | reversedList.forEach(function (key) {
|
3389 | var _a = _this.resolveVariant(_this.variants[key]), target = _a.target, transitionEnd = _a.transitionEnd;
|
3390 | if (transitionEnd) {
|
3391 | _this.setValues(transitionEnd, { isActive: isActive });
|
3392 | }
|
3393 | if (target) {
|
3394 | _this.setValues(target, { isActive: isActive });
|
3395 | }
|
3396 | if (_this.children && _this.children.size) {
|
3397 | _this.children.forEach(function (child) {
|
3398 | return child.applyVariantLabels(variantLabelList);
|
3399 | });
|
3400 | }
|
3401 | });
|
3402 | };
|
3403 | VisualElementAnimationControls.prototype.start = function (definition, opts) {
|
3404 | var _this = this;
|
3405 | if (opts === void 0) { opts = {}; }
|
3406 | if (opts.priority) {
|
3407 | this.activeOverrides.add(opts.priority);
|
3408 | }
|
3409 | this.resetIsAnimating(opts.priority);
|
3410 | var animation;
|
3411 | if (isVariantLabels(definition)) {
|
3412 | animation = this.animateVariantLabels(definition, opts);
|
3413 | }
|
3414 | else if (typeof definition === "string") {
|
3415 | animation = this.animateVariant(definition, opts);
|
3416 | }
|
3417 | else {
|
3418 | animation = this.animate(definition, opts);
|
3419 | }
|
3420 | this.onStart();
|
3421 | return animation.then(function () { return _this.onComplete(); });
|
3422 | };
|
3423 | VisualElementAnimationControls.prototype.animate = function (animationDefinition, _a) {
|
3424 | var _this = this;
|
3425 | var _b = _a === void 0 ? {} : _a, _c = _b.delay, delay = _c === void 0 ? 0 : _c, _d = _b.priority, priority = _d === void 0 ? 0 : _d, transitionOverride = _b.transitionOverride;
|
3426 | var _e = this.resolveVariant(animationDefinition), target = _e.target, transition = _e.transition, transitionEnd = _e.transitionEnd;
|
3427 | if (transitionOverride) {
|
3428 | transition = transitionOverride;
|
3429 | }
|
3430 | if (!target)
|
3431 | return Promise.resolve();
|
3432 | target = this.transformValues(target);
|
3433 | if (transitionEnd) {
|
3434 | transitionEnd = this.transformValues(transitionEnd);
|
3435 | }
|
3436 | this.checkForNewValues(target);
|
3437 | var origin = this.transformValues(getOrigin(target, transition, this.visualElement));
|
3438 | if (this.makeTargetAnimatable) {
|
3439 | var animatable = this.makeTargetAnimatable(this.visualElement, target, origin, transitionEnd);
|
3440 | target = animatable.target;
|
3441 | transitionEnd = animatable.transitionEnd;
|
3442 | }
|
3443 | if (priority) {
|
3444 | this.resolvedOverrides[priority] = target;
|
3445 | }
|
3446 | this.checkForNewValues(target);
|
3447 | var animations = [];
|
3448 | for (var key in target) {
|
3449 | var value = this.visualElement.getValue(key);
|
3450 | if (!value || !target || target[key] === undefined)
|
3451 | continue;
|
3452 | var valueTarget = target[key];
|
3453 | if (!priority) {
|
3454 | this.baseTarget[key] = resolveFinalValueInKeyframes(valueTarget);
|
3455 | }
|
3456 | if (this.isAnimating.has(key))
|
3457 | continue;
|
3458 | this.isAnimating.add(key);
|
3459 | animations.push(startAnimation(key, value, valueTarget, __assign({ delay: delay }, transition)));
|
3460 | }
|
3461 | var allAnimations = Promise.all(animations);
|
3462 | return transitionEnd
|
3463 | ? allAnimations.then(function () {
|
3464 | _this.setValues(transitionEnd, { priority: priority });
|
3465 | })
|
3466 | : allAnimations;
|
3467 | };
|
3468 | VisualElementAnimationControls.prototype.animateVariantLabels = function (variantLabels, opts) {
|
3469 | var _this = this;
|
3470 | var animations = __spreadArrays(variantLabels).reverse()
|
3471 | .map(function (label) { return _this.animateVariant(label, opts); });
|
3472 | return Promise.all(animations);
|
3473 | };
|
3474 | VisualElementAnimationControls.prototype.animateVariant = function (variantLabel, opts) {
|
3475 | var _this = this;
|
3476 | var when = false;
|
3477 | var delayChildren = 0;
|
3478 | var staggerChildren = 0;
|
3479 | var staggerDirection = 1;
|
3480 | var priority = (opts && opts.priority) || 0;
|
3481 | var variant = this.variants[variantLabel];
|
3482 | var getAnimations = variant
|
3483 | ? function () { return _this.animate(variant, opts); }
|
3484 | : function () { return Promise.resolve(); };
|
3485 | var getChildrenAnimations = this.children
|
3486 | ? function () {
|
3487 | return _this.animateChildren(variantLabel, delayChildren, staggerChildren, staggerDirection, priority);
|
3488 | }
|
3489 | : function () { return Promise.resolve(); };
|
3490 | if (variant && this.children) {
|
3491 | var transition = this.resolveVariant(variant).transition;
|
3492 | if (transition) {
|
3493 | when = transition.when || when;
|
3494 | delayChildren = transition.delayChildren || delayChildren;
|
3495 | staggerChildren = transition.staggerChildren || staggerChildren;
|
3496 | staggerDirection =
|
3497 | transition.staggerDirection || staggerDirection;
|
3498 | }
|
3499 | }
|
3500 | if (when) {
|
3501 | var _a = when === "beforeChildren"
|
3502 | ? [getAnimations, getChildrenAnimations]
|
3503 | : [getChildrenAnimations, getAnimations], first = _a[0], last = _a[1];
|
3504 | return first().then(last);
|
3505 | }
|
3506 | else {
|
3507 | return Promise.all([getAnimations(), getChildrenAnimations()]);
|
3508 | }
|
3509 | };
|
3510 | VisualElementAnimationControls.prototype.animateChildren = function (variantLabel, delayChildren, staggerChildren, staggerDirection, priority) {
|
3511 | if (delayChildren === void 0) { delayChildren = 0; }
|
3512 | if (staggerChildren === void 0) { staggerChildren = 0; }
|
3513 | if (staggerDirection === void 0) { staggerDirection = 1; }
|
3514 | if (priority === void 0) { priority = 0; }
|
3515 | if (!this.children) {
|
3516 | return Promise.resolve();
|
3517 | }
|
3518 | var animations = [];
|
3519 | var maxStaggerDuration = (this.children.size - 1) * staggerChildren;
|
3520 | var generateStaggerDuration = staggerDirection === 1
|
3521 | ? function (i) { return i * staggerChildren; }
|
3522 | : function (i) { return maxStaggerDuration - i * staggerChildren; };
|
3523 | Array.from(this.children).forEach(function (childControls, i) {
|
3524 | var animation = childControls.animateVariant(variantLabel, {
|
3525 | priority: priority,
|
3526 | delay: delayChildren + generateStaggerDuration(i),
|
3527 | });
|
3528 | animations.push(animation);
|
3529 | });
|
3530 | return Promise.all(animations);
|
3531 | };
|
3532 | VisualElementAnimationControls.prototype.onStart = function () {
|
3533 | var onAnimationStart = this.props.onAnimationStart;
|
3534 | onAnimationStart && onAnimationStart();
|
3535 | };
|
3536 | VisualElementAnimationControls.prototype.onComplete = function () {
|
3537 | var onAnimationComplete = this.props.onAnimationComplete;
|
3538 | onAnimationComplete && onAnimationComplete();
|
3539 | };
|
3540 | VisualElementAnimationControls.prototype.checkOverrideIsAnimating = function (priority) {
|
3541 | var numOverrides = this.overrides.length;
|
3542 | for (var i = priority + 1; i < numOverrides; i++) {
|
3543 | var resolvedOverride = this.resolvedOverrides[i];
|
3544 | if (resolvedOverride) {
|
3545 | for (var key in resolvedOverride) {
|
3546 | this.isAnimating.add(key);
|
3547 | }
|
3548 | }
|
3549 | }
|
3550 | };
|
3551 | VisualElementAnimationControls.prototype.resetIsAnimating = function (priority) {
|
3552 | if (priority === void 0) { priority = 0; }
|
3553 | this.isAnimating.clear();
|
3554 |
|
3555 |
|
3556 | if (priority < this.getHighestPriority()) {
|
3557 | this.checkOverrideIsAnimating(priority);
|
3558 | }
|
3559 | if (this.children) {
|
3560 | this.children.forEach(function (child) { return child.resetIsAnimating(priority); });
|
3561 | }
|
3562 | };
|
3563 | VisualElementAnimationControls.prototype.stop = function () {
|
3564 | this.visualElement.forEachValue(function (value) { return value.stop(); });
|
3565 | };
|
3566 | |
3567 |
|
3568 |
|
3569 |
|
3570 | VisualElementAnimationControls.prototype.addChild = function (controls) {
|
3571 | if (!this.children) {
|
3572 | this.children = new Set();
|
3573 | }
|
3574 | this.children.add(controls);
|
3575 |
|
3576 |
|
3577 | this.overrides.forEach(function (override, i) {
|
3578 | override && controls.setOverride(override, i);
|
3579 | });
|
3580 | };
|
3581 | VisualElementAnimationControls.prototype.removeChild = function (controls) {
|
3582 | if (!this.children) {
|
3583 | return;
|
3584 | }
|
3585 | this.children.delete(controls);
|
3586 | };
|
3587 | VisualElementAnimationControls.prototype.resetChildren = function () {
|
3588 | if (this.children)
|
3589 | this.children.clear();
|
3590 | };
|
3591 | return VisualElementAnimationControls;
|
3592 | }());
|
3593 | function getOriginFromTransition(key, transition) {
|
3594 | if (!transition)
|
3595 | return;
|
3596 | var valueTransition = transition[key] || transition["default"] || transition;
|
3597 | return valueTransition.from;
|
3598 | }
|
3599 | function getOrigin(target, transition, visualElement) {
|
3600 | var _a, _b;
|
3601 | var origin = {};
|
3602 | for (var key in target) {
|
3603 | origin[key] = (_a = getOriginFromTransition(key, transition)) !== null && _a !== void 0 ? _a : (_b = visualElement.getValue(key)) === null || _b === void 0 ? void 0 : _b.get();
|
3604 | }
|
3605 | return origin;
|
3606 | }
|
3607 |
|
3608 |
|
3609 |
|
3610 |
|
3611 |
|
3612 |
|
3613 |
|
3614 |
|
3615 | function useVisualElementAnimation(visualElement, props, config) {
|
3616 | var subscribeToParentControls = checkShouldInheritVariant(props);
|
3617 | var variants = props.variants, transition = props.transition;
|
3618 | var parentControls = useContext(MotionContext).controls;
|
3619 | var presenceContext = useContext(PresenceContext);
|
3620 | var controls = useConstant(function () { return new VisualElementAnimationControls(visualElement, config); });
|
3621 |
|
3622 | if (!presenceContext || presenceContext.isPresent) {
|
3623 | controls.resetChildren();
|
3624 | controls.setProps(props);
|
3625 | controls.setVariants(variants);
|
3626 | controls.setDefaultTransition(transition);
|
3627 | }
|
3628 |
|
3629 |
|
3630 | useEffect(function () {
|
3631 | if (subscribeToParentControls && parentControls) {
|
3632 | parentControls.addChild(controls);
|
3633 | }
|
3634 | });
|
3635 | useEffect(function () {
|
3636 | return function () {
|
3637 |
|
3638 |
|
3639 |
|
3640 | var onAnimationComplete = props.onAnimationComplete, unmountProps = __rest(props, ["onAnimationComplete"]);
|
3641 | controls.setProps(unmountProps);
|
3642 | parentControls && parentControls.removeChild(controls);
|
3643 | };
|
3644 | }, []);
|
3645 | return controls;
|
3646 | }
|
3647 |
|
3648 |
|
3649 |
|
3650 |
|
3651 | var MotionConfigContext = createContext({
|
3652 | transformPagePoint: function (p) { return p; },
|
3653 | features: [],
|
3654 | });
|
3655 |
|
3656 |
|
3657 |
|
3658 |
|
3659 |
|
3660 |
|
3661 |
|
3662 |
|
3663 |
|
3664 |
|
3665 |
|
3666 |
|
3667 |
|
3668 |
|
3669 |
|
3670 |
|
3671 |
|
3672 |
|
3673 |
|
3674 |
|
3675 |
|
3676 |
|
3677 | function MotionConfig(_a) {
|
3678 | var children = _a.children, _b = _a.features, features = _b === void 0 ? [] : _b, props = __rest(_a, ["children", "features"]);
|
3679 | var pluginContext = useContext(MotionConfigContext);
|
3680 | var loadedFeatures = __spreadArrays(pluginContext.features, features);
|
3681 |
|
3682 | var value = useMemo(function () { return ({ features: loadedFeatures }); }, [
|
3683 | loadedFeatures.length,
|
3684 | ]);
|
3685 |
|
3686 |
|
3687 | for (var key in props) {
|
3688 | value[key] = props[key];
|
3689 | }
|
3690 | return (createElement(MotionConfigContext.Provider, { value: value }, children));
|
3691 | }
|
3692 |
|
3693 |
|
3694 |
|
3695 |
|
3696 | function useFeatures(defaultFeatures, isStatic, visualElement, controls, props, context, parentContext, shouldInheritVariant) {
|
3697 | var plugins = useContext(MotionConfigContext);
|
3698 |
|
3699 |
|
3700 | if (isStatic || typeof window === "undefined")
|
3701 | return null;
|
3702 | var allFeatures = __spreadArrays(defaultFeatures, plugins.features);
|
3703 | var numFeatures = allFeatures.length;
|
3704 | var features = [];
|
3705 |
|
3706 | for (var i = 0; i < numFeatures; i++) {
|
3707 | var _a = allFeatures[i], shouldRender = _a.shouldRender, key = _a.key, getComponent = _a.getComponent;
|
3708 | if (shouldRender(props, parentContext)) {
|
3709 | var Component = getComponent(props);
|
3710 | Component &&
|
3711 | features.push(createElement(Component, __assign({ key: key }, props, { localContext: context, parentContext: parentContext, visualElement: visualElement, controls: controls, inherit: shouldInheritVariant })));
|
3712 | }
|
3713 | }
|
3714 | return features;
|
3715 | }
|
3716 |
|
3717 | var Presence;
|
3718 | (function (Presence) {
|
3719 | Presence[Presence["Entering"] = 0] = "Entering";
|
3720 | Presence[Presence["Present"] = 1] = "Present";
|
3721 | Presence[Presence["Exiting"] = 2] = "Exiting";
|
3722 | })(Presence || (Presence = {}));
|
3723 | var VisibilityAction;
|
3724 | (function (VisibilityAction) {
|
3725 | VisibilityAction[VisibilityAction["Hide"] = 0] = "Hide";
|
3726 | VisibilityAction[VisibilityAction["Show"] = 1] = "Show";
|
3727 | })(VisibilityAction || (VisibilityAction = {}));
|
3728 |
|
3729 |
|
3730 |
|
3731 |
|
3732 | var defaultHandler = {
|
3733 | measureLayout: function (child) { return child.measureLayout(); },
|
3734 | layoutReady: function (child) { return child.layoutReady(); },
|
3735 | };
|
3736 |
|
3737 |
|
3738 |
|
3739 | var sortByDepth = function (a, b) {
|
3740 | return a.depth - b.depth;
|
3741 | };
|
3742 |
|
3743 |
|
3744 |
|
3745 | function createBatcher() {
|
3746 | var queue = new Set();
|
3747 | var add = function (child) { return queue.add(child); };
|
3748 | var flush = function (_a) {
|
3749 | var _b = _a === void 0 ? defaultHandler : _a, measureLayout = _b.measureLayout, layoutReady = _b.layoutReady;
|
3750 | var order = Array.from(queue).sort(sortByDepth);
|
3751 | |
3752 |
|
3753 |
|
3754 | order.forEach(function (child) { return child.resetTransform(); });
|
3755 | |
3756 |
|
3757 |
|
3758 | order.forEach(measureLayout);
|
3759 | |
3760 |
|
3761 |
|
3762 | order.forEach(layoutReady);
|
3763 | |
3764 |
|
3765 |
|
3766 |
|
3767 |
|
3768 |
|
3769 | order.forEach(function (child) {
|
3770 | if (child.isPresent)
|
3771 | child.presence = Presence.Present;
|
3772 | });
|
3773 | queue.clear();
|
3774 | };
|
3775 | return { add: add, flush: flush };
|
3776 | }
|
3777 | function isSharedLayout(context) {
|
3778 | return !!context.forceUpdate;
|
3779 | }
|
3780 | var SharedLayoutContext = createContext(createBatcher());
|
3781 |
|
3782 | function useUnmountEffect(callback) {
|
3783 | return useEffect(function () { return function () { return callback(); }; }, []);
|
3784 | }
|
3785 |
|
3786 | function useSnapshotOnUnmount(visualElement) {
|
3787 | var syncLayout = useContext(SharedLayoutContext);
|
3788 | useUnmountEffect(function () {
|
3789 | if (isSharedLayout(syncLayout))
|
3790 | syncLayout.remove(visualElement);
|
3791 | });
|
3792 | }
|
3793 |
|
3794 |
|
3795 |
|
3796 |
|
3797 |
|
3798 |
|
3799 |
|
3800 |
|
3801 |
|
3802 |
|
3803 |
|
3804 |
|
3805 | function createMotionComponent(Component, _a) {
|
3806 | var defaultFeatures = _a.defaultFeatures, useVisualElement = _a.useVisualElement, render = _a.render, animationControlsConfig = _a.animationControlsConfig;
|
3807 | function MotionComponent(props, externalRef) {
|
3808 | var parentContext = useContext(MotionContext);
|
3809 | var shouldInheritVariant = checkShouldInheritVariant(props);
|
3810 | |
3811 |
|
3812 |
|
3813 |
|
3814 |
|
3815 |
|
3816 | var isStatic = parentContext.static || props.static || false;
|
3817 | |
3818 |
|
3819 |
|
3820 |
|
3821 |
|
3822 |
|
3823 | var visualElement = useVisualElement(Component, props, parentContext.visualElement, isStatic, externalRef);
|
3824 | |
3825 |
|
3826 |
|
3827 |
|
3828 | useMotionValues(visualElement, props);
|
3829 | |
3830 |
|
3831 |
|
3832 |
|
3833 | var controls = useVisualElementAnimation(visualElement, props, animationControlsConfig);
|
3834 | |
3835 |
|
3836 |
|
3837 | var context = useMotionContext(parentContext, controls, visualElement, isStatic, props);
|
3838 | |
3839 |
|
3840 |
|
3841 | var features = useFeatures(defaultFeatures, isStatic, visualElement, controls, props, context, parentContext, shouldInheritVariant);
|
3842 | var component = render(Component, props, visualElement);
|
3843 | |
3844 |
|
3845 |
|
3846 | useSnapshotOnUnmount(visualElement);
|
3847 |
|
3848 |
|
3849 | return (createElement(Fragment, null,
|
3850 | createElement(MotionContext.Provider, { value: context }, component),
|
3851 | features));
|
3852 | }
|
3853 | return forwardRef(MotionComponent);
|
3854 | }
|
3855 |
|
3856 | function createLock(name) {
|
3857 | var lock = null;
|
3858 | return function () {
|
3859 | var openLock = function () {
|
3860 | lock = null;
|
3861 | };
|
3862 | if (lock === null) {
|
3863 | lock = name;
|
3864 | return openLock;
|
3865 | }
|
3866 | return false;
|
3867 | };
|
3868 | }
|
3869 | var globalHorizontalLock = createLock("dragHorizontal");
|
3870 | var globalVerticalLock = createLock("dragVertical");
|
3871 | function getGlobalLock(drag) {
|
3872 | var lock = false;
|
3873 | if (drag === "y") {
|
3874 | lock = globalVerticalLock();
|
3875 | }
|
3876 | else if (drag === "x") {
|
3877 | lock = globalHorizontalLock();
|
3878 | }
|
3879 | else {
|
3880 | var openHorizontal_1 = globalHorizontalLock();
|
3881 | var openVertical_1 = globalVerticalLock();
|
3882 | if (openHorizontal_1 && openVertical_1) {
|
3883 | lock = function () {
|
3884 | openHorizontal_1();
|
3885 | openVertical_1();
|
3886 | };
|
3887 | }
|
3888 | else {
|
3889 |
|
3890 | if (openHorizontal_1)
|
3891 | openHorizontal_1();
|
3892 | if (openVertical_1)
|
3893 | openVertical_1();
|
3894 | }
|
3895 | }
|
3896 | return lock;
|
3897 | }
|
3898 |
|
3899 | var isViewportScrollBlocked = false;
|
3900 | var isBrowser = typeof window !== "undefined";
|
3901 | if (isBrowser) {
|
3902 | document.addEventListener("touchmove", function (event) {
|
3903 | if (isViewportScrollBlocked) {
|
3904 | event.preventDefault();
|
3905 | }
|
3906 | }, { passive: false });
|
3907 | }
|
3908 | var blockViewportScroll = function () { return (isViewportScrollBlocked = true); };
|
3909 | var unblockViewportScroll = function () { return (isViewportScrollBlocked = false); };
|
3910 |
|
3911 | function addDomEvent(target, eventName, handler, options) {
|
3912 | if (!handler)
|
3913 | return;
|
3914 | target.addEventListener(eventName, handler, options);
|
3915 | return function () { return target.removeEventListener(eventName, handler, options); };
|
3916 | }
|
3917 |
|
3918 |
|
3919 |
|
3920 |
|
3921 |
|
3922 |
|
3923 |
|
3924 |
|
3925 |
|
3926 |
|
3927 |
|
3928 |
|
3929 |
|
3930 |
|
3931 |
|
3932 |
|
3933 |
|
3934 |
|
3935 |
|
3936 |
|
3937 |
|
3938 | function useDomEvent(ref, eventName, handler, options) {
|
3939 | useEffect(function () {
|
3940 | var element = ref.current;
|
3941 | if (handler && element) {
|
3942 | return addDomEvent(element, eventName, handler, options);
|
3943 | }
|
3944 | }, [ref, eventName, handler, options]);
|
3945 | }
|
3946 |
|
3947 | function isMouseEvent(event) {
|
3948 |
|
3949 | if (typeof PointerEvent !== "undefined" && event instanceof PointerEvent) {
|
3950 | return !!(event.pointerType === "mouse");
|
3951 | }
|
3952 | return event instanceof MouseEvent;
|
3953 | }
|
3954 | function isTouchEvent(event) {
|
3955 | var hasTouches = !!event.touches;
|
3956 | return hasTouches;
|
3957 | }
|
3958 |
|
3959 |
|
3960 |
|
3961 |
|
3962 |
|
3963 | function filterPrimaryPointer(eventHandler) {
|
3964 | if (!eventHandler)
|
3965 | return undefined;
|
3966 | return function (event) {
|
3967 | var isMouseEvent = event instanceof MouseEvent;
|
3968 | var isPrimaryPointer = !isMouseEvent ||
|
3969 | (isMouseEvent && event.button === 0);
|
3970 | if (isPrimaryPointer) {
|
3971 | eventHandler(event);
|
3972 | }
|
3973 | };
|
3974 | }
|
3975 | var defaultPagePoint = { pageX: 0, pageY: 0 };
|
3976 | function pointFromTouch(e, pointType) {
|
3977 | if (pointType === void 0) { pointType = "page"; }
|
3978 | var primaryTouch = e.touches[0] || e.changedTouches[0];
|
3979 | var point = primaryTouch || defaultPagePoint;
|
3980 | return {
|
3981 | x: point[pointType + "X"],
|
3982 | y: point[pointType + "Y"],
|
3983 | };
|
3984 | }
|
3985 | function pointFromMouse(point, pointType) {
|
3986 | if (pointType === void 0) { pointType = "page"; }
|
3987 | return {
|
3988 | x: point[pointType + "X"],
|
3989 | y: point[pointType + "Y"],
|
3990 | };
|
3991 | }
|
3992 | function extractEventInfo(event, pointType) {
|
3993 | if (pointType === void 0) { pointType = "page"; }
|
3994 | return {
|
3995 | point: isTouchEvent(event)
|
3996 | ? pointFromTouch(event, pointType)
|
3997 | : pointFromMouse(event, pointType),
|
3998 | };
|
3999 | }
|
4000 | function getViewportPointFromEvent(event) {
|
4001 | return extractEventInfo(event, "client");
|
4002 | }
|
4003 | var wrapHandler = function (handler, shouldFilterPrimaryPointer) {
|
4004 | if (shouldFilterPrimaryPointer === void 0) { shouldFilterPrimaryPointer = false; }
|
4005 | if (!handler)
|
4006 | return;
|
4007 | var listener = function (event) { return handler(event, extractEventInfo(event)); };
|
4008 | return shouldFilterPrimaryPointer
|
4009 | ? filterPrimaryPointer(listener)
|
4010 | : listener;
|
4011 | };
|
4012 |
|
4013 | var isBrowser$1 = typeof window !== "undefined";
|
4014 |
|
4015 | var supportsPointerEvents = function () {
|
4016 | return isBrowser$1 && window.onpointerdown === null;
|
4017 | };
|
4018 | var supportsTouchEvents = function () {
|
4019 | return isBrowser$1 && window.ontouchstart === null;
|
4020 | };
|
4021 | var supportsMouseEvents = function () {
|
4022 | return isBrowser$1 && window.onmousedown === null;
|
4023 | };
|
4024 |
|
4025 | var mouseEventNames = {
|
4026 | pointerdown: "mousedown",
|
4027 | pointermove: "mousemove",
|
4028 | pointerup: "mouseup",
|
4029 | pointercancel: "mousecancel",
|
4030 | pointerover: "mouseover",
|
4031 | pointerout: "mouseout",
|
4032 | pointerenter: "mouseenter",
|
4033 | pointerleave: "mouseleave",
|
4034 | };
|
4035 | var touchEventNames = {
|
4036 | pointerdown: "touchstart",
|
4037 | pointermove: "touchmove",
|
4038 | pointerup: "touchend",
|
4039 | pointercancel: "touchcancel",
|
4040 | };
|
4041 | function getPointerEventName(name) {
|
4042 | if (supportsPointerEvents()) {
|
4043 | return name;
|
4044 | }
|
4045 | else if (supportsTouchEvents()) {
|
4046 | return touchEventNames[name];
|
4047 | }
|
4048 | else if (supportsMouseEvents()) {
|
4049 | return mouseEventNames[name];
|
4050 | }
|
4051 | return name;
|
4052 | }
|
4053 | function addPointerEvent(target, eventName, handler, options) {
|
4054 | return addDomEvent(target, getPointerEventName(eventName), wrapHandler(handler, eventName === "pointerdown"), options);
|
4055 | }
|
4056 | function usePointerEvent(ref, eventName, handler, options) {
|
4057 | return useDomEvent(ref, getPointerEventName(eventName), wrapHandler(handler, eventName === "pointerdown"), options);
|
4058 | }
|
4059 |
|
4060 |
|
4061 | var Point;
|
4062 | (function (Point) {
|
4063 |
|
4064 | Point.subtract = function (a, b) {
|
4065 | return { x: a.x - b.x, y: a.y - b.y };
|
4066 | };
|
4067 |
|
4068 | Point.relativeTo = function (idOrElem) {
|
4069 | var elem;
|
4070 | var getElem = function () {
|
4071 |
|
4072 | if (elem !== undefined)
|
4073 | return elem;
|
4074 | if (typeof idOrElem === "string") {
|
4075 | elem = document.getElementById(idOrElem);
|
4076 | }
|
4077 | else {
|
4078 | elem = idOrElem;
|
4079 | }
|
4080 | return elem;
|
4081 | };
|
4082 | return function (_a) {
|
4083 | var x = _a.x, y = _a.y;
|
4084 | var localElem = getElem();
|
4085 | if (!localElem)
|
4086 | return undefined;
|
4087 | var rect = localElem.getBoundingClientRect();
|
4088 | return {
|
4089 | x: x - rect.left - window.scrollX,
|
4090 | y: y - rect.top - window.scrollY,
|
4091 | };
|
4092 | };
|
4093 | };
|
4094 | })(Point || (Point = {}));
|
4095 |
|
4096 |
|
4097 |
|
4098 |
|
4099 | var PanSession = (function () {
|
4100 | function PanSession(event, handlers, _a) {
|
4101 | var _this = this;
|
4102 | var transformPagePoint = (_a === void 0 ? {} : _a).transformPagePoint;
|
4103 | |
4104 |
|
4105 |
|
4106 | this.startEvent = null;
|
4107 | |
4108 |
|
4109 |
|
4110 | this.lastMoveEvent = null;
|
4111 | |
4112 |
|
4113 |
|
4114 | this.lastMoveEventInfo = null;
|
4115 | |
4116 |
|
4117 |
|
4118 | this.handlers = {};
|
4119 | this.updatePoint = function () {
|
4120 | if (!(_this.lastMoveEvent && _this.lastMoveEventInfo))
|
4121 | return;
|
4122 | var info = getPanInfo(_this.lastMoveEventInfo, _this.history);
|
4123 | var isPanStarted = _this.startEvent !== null;
|
4124 |
|
4125 |
|
4126 |
|
4127 | var isDistancePastThreshold = distance(info.offset, { x: 0, y: 0 }) >= 3;
|
4128 | if (!isPanStarted && !isDistancePastThreshold)
|
4129 | return;
|
4130 | var point = info.point;
|
4131 | var timestamp = getFrameData().timestamp;
|
4132 | _this.history.push(__assign(__assign({}, point), { timestamp: timestamp }));
|
4133 | var _a = _this.handlers, onStart = _a.onStart, onMove = _a.onMove;
|
4134 | if (!isPanStarted) {
|
4135 | onStart && onStart(_this.lastMoveEvent, info);
|
4136 | _this.startEvent = _this.lastMoveEvent;
|
4137 | }
|
4138 | onMove && onMove(_this.lastMoveEvent, info);
|
4139 | };
|
4140 |
|
4141 | if (isTouchEvent(event) && event.touches.length > 1)
|
4142 | return;
|
4143 | this.handlers = handlers;
|
4144 | this.transformPagePoint = transformPagePoint;
|
4145 | var info = extractEventInfo(event);
|
4146 | var initialInfo = transformPoint(info, this.transformPagePoint);
|
4147 | var point = initialInfo.point;
|
4148 | var timestamp = getFrameData().timestamp;
|
4149 | this.history = [__assign(__assign({}, point), { timestamp: timestamp })];
|
4150 | var onSessionStart = handlers.onSessionStart;
|
4151 | onSessionStart &&
|
4152 | onSessionStart(event, getPanInfo(initialInfo, this.history));
|
4153 | var removeOnPointerMove = addPointerEvent(window, "pointermove", function (event, info) { return _this.handlePointerMove(event, info); });
|
4154 | var removeOnPointerUp = addPointerEvent(window, "pointerup", function (event, info) { return _this.handlePointerUp(event, info); });
|
4155 | this.removeListeners = function () {
|
4156 | removeOnPointerMove && removeOnPointerMove();
|
4157 | removeOnPointerUp && removeOnPointerUp();
|
4158 | };
|
4159 | }
|
4160 | PanSession.prototype.handlePointerMove = function (event, info) {
|
4161 | this.lastMoveEvent = event;
|
4162 | this.lastMoveEventInfo = transformPoint(info, this.transformPagePoint);
|
4163 |
|
4164 | if (isMouseEvent(event) && event.buttons === 0) {
|
4165 | this.handlePointerUp(event, info);
|
4166 | return;
|
4167 | }
|
4168 |
|
4169 | sync.update(this.updatePoint, true);
|
4170 | };
|
4171 | PanSession.prototype.handlePointerUp = function (event, info) {
|
4172 | this.end();
|
4173 | var onEnd = this.handlers.onEnd;
|
4174 | if (!onEnd)
|
4175 | return;
|
4176 | var panInfo = getPanInfo(transformPoint(info, this.transformPagePoint), this.history);
|
4177 | onEnd && onEnd(event, panInfo);
|
4178 | };
|
4179 | PanSession.prototype.updateHandlers = function (handlers) {
|
4180 | this.handlers = handlers;
|
4181 | };
|
4182 | PanSession.prototype.end = function () {
|
4183 | this.removeListeners && this.removeListeners();
|
4184 | cancelSync.update(this.updatePoint);
|
4185 | unblockViewportScroll();
|
4186 | };
|
4187 | return PanSession;
|
4188 | }());
|
4189 | function transformPoint(info, transformPagePoint) {
|
4190 | return transformPagePoint ? { point: transformPagePoint(info.point) } : info;
|
4191 | }
|
4192 | function getPanInfo(_a, history) {
|
4193 | var point = _a.point;
|
4194 | return {
|
4195 | point: point,
|
4196 | delta: Point.subtract(point, lastDevicePoint(history)),
|
4197 | offset: Point.subtract(point, startDevicePoint(history)),
|
4198 | velocity: getVelocity$1(history, 0.1),
|
4199 | };
|
4200 | }
|
4201 | function startDevicePoint(history) {
|
4202 | return history[0];
|
4203 | }
|
4204 | function lastDevicePoint(history) {
|
4205 | return history[history.length - 1];
|
4206 | }
|
4207 | function getVelocity$1(history, timeDelta) {
|
4208 | if (history.length < 2) {
|
4209 | return { x: 0, y: 0 };
|
4210 | }
|
4211 | var i = history.length - 1;
|
4212 | var timestampedPoint = null;
|
4213 | var lastPoint = lastDevicePoint(history);
|
4214 | while (i >= 0) {
|
4215 | timestampedPoint = history[i];
|
4216 | if (lastPoint.timestamp - timestampedPoint.timestamp >
|
4217 | secondsToMilliseconds(timeDelta)) {
|
4218 | break;
|
4219 | }
|
4220 | i--;
|
4221 | }
|
4222 | if (!timestampedPoint) {
|
4223 | return { x: 0, y: 0 };
|
4224 | }
|
4225 | var time = (lastPoint.timestamp - timestampedPoint.timestamp) / 1000;
|
4226 | if (time === 0) {
|
4227 | return { x: 0, y: 0 };
|
4228 | }
|
4229 | var currentVelocity = {
|
4230 | x: (lastPoint.x - timestampedPoint.x) / time,
|
4231 | y: (lastPoint.y - timestampedPoint.y) / time,
|
4232 | };
|
4233 | if (currentVelocity.x === Infinity) {
|
4234 | currentVelocity.x = 0;
|
4235 | }
|
4236 | if (currentVelocity.y === Infinity) {
|
4237 | currentVelocity.y = 0;
|
4238 | }
|
4239 | return currentVelocity;
|
4240 | }
|
4241 |
|
4242 |
|
4243 |
|
4244 |
|
4245 |
|
4246 |
|
4247 | function applyConstraints(point, _a, elastic) {
|
4248 | var min = _a.min, max = _a.max;
|
4249 | if (min !== undefined && point < min) {
|
4250 |
|
4251 | point = elastic ? mix(min, point, elastic) : Math.max(point, min);
|
4252 | }
|
4253 | else if (max !== undefined && point > max) {
|
4254 |
|
4255 | point = elastic ? mix(max, point, elastic) : Math.min(point, max);
|
4256 | }
|
4257 | return point;
|
4258 | }
|
4259 |
|
4260 |
|
4261 |
|
4262 |
|
4263 |
|
4264 |
|
4265 |
|
4266 |
|
4267 | function calcConstrainedMinPoint(point, length, progress, constraints, elastic) {
|
4268 |
|
4269 | var min = point - length * progress;
|
4270 | return constraints ? applyConstraints(min, constraints, elastic) : min;
|
4271 | }
|
4272 |
|
4273 |
|
4274 |
|
4275 |
|
4276 | function calcRelativeAxisConstraints(axis, min, max) {
|
4277 | var constraints = {};
|
4278 | var length = axis.max - axis.min;
|
4279 | if (min !== undefined) {
|
4280 | constraints.min = axis.min + min;
|
4281 | }
|
4282 | if (max !== undefined) {
|
4283 | constraints.max = Math.max(axis.min + max - length, axis.min);
|
4284 | }
|
4285 | return constraints;
|
4286 | }
|
4287 |
|
4288 |
|
4289 |
|
4290 |
|
4291 | function calcRelativeConstraints(layoutBox, _a) {
|
4292 | var top = _a.top, left = _a.left, bottom = _a.bottom, right = _a.right;
|
4293 | return {
|
4294 | x: calcRelativeAxisConstraints(layoutBox.x, left, right),
|
4295 | y: calcRelativeAxisConstraints(layoutBox.y, top, bottom),
|
4296 | };
|
4297 | }
|
4298 |
|
4299 |
|
4300 |
|
4301 | function calcViewportAxisConstraints(layoutAxis, constraintsAxis) {
|
4302 | var _a;
|
4303 | var min = constraintsAxis.min - layoutAxis.min;
|
4304 | var max = constraintsAxis.max - layoutAxis.max;
|
4305 |
|
4306 |
|
4307 | if (constraintsAxis.max - constraintsAxis.min <
|
4308 | layoutAxis.max - layoutAxis.min) {
|
4309 | _a = [max, min], min = _a[0], max = _a[1];
|
4310 | }
|
4311 | return {
|
4312 | min: layoutAxis.min + min,
|
4313 | max: layoutAxis.min + max,
|
4314 | };
|
4315 | }
|
4316 |
|
4317 |
|
4318 |
|
4319 | function calcViewportConstraints(layoutBox, constraintsBox) {
|
4320 | return {
|
4321 | x: calcViewportAxisConstraints(layoutBox.x, constraintsBox.x),
|
4322 | y: calcViewportAxisConstraints(layoutBox.y, constraintsBox.y),
|
4323 | };
|
4324 | }
|
4325 |
|
4326 |
|
4327 |
|
4328 | function calcPositionFromProgress(axis, constraints, progress) {
|
4329 | var axisLength = axis.max - axis.min;
|
4330 | var min = mix(constraints.min, constraints.max - axisLength, progress);
|
4331 | return { min: min, max: min + axisLength };
|
4332 | }
|
4333 |
|
4334 | var elementDragControls = new WeakMap();
|
4335 |
|
4336 |
|
4337 |
|
4338 | var lastPointerEvent;
|
4339 | var VisualElementDragControls = (function () {
|
4340 | function VisualElementDragControls(_a) {
|
4341 | var visualElement = _a.visualElement;
|
4342 | |
4343 |
|
4344 |
|
4345 |
|
4346 |
|
4347 | this.isDragging = false;
|
4348 | |
4349 |
|
4350 |
|
4351 |
|
4352 |
|
4353 | this.currentDirection = null;
|
4354 | |
4355 |
|
4356 |
|
4357 |
|
4358 |
|
4359 | this.constraints = false;
|
4360 | |
4361 |
|
4362 |
|
4363 |
|
4364 |
|
4365 | this.props = {};
|
4366 | |
4367 |
|
4368 |
|
4369 |
|
4370 |
|
4371 |
|
4372 |
|
4373 | this.cursorProgress = {
|
4374 | x: 0.5,
|
4375 | y: 0.5,
|
4376 | };
|
4377 |
|
4378 |
|
4379 |
|
4380 | this.openGlobalLock = null;
|
4381 | |
4382 |
|
4383 |
|
4384 | this.panSession = null;
|
4385 | this.visualElement = visualElement;
|
4386 | this.visualElement.enableLayoutProjection();
|
4387 | elementDragControls.set(visualElement, this);
|
4388 | }
|
4389 | |
4390 |
|
4391 |
|
4392 |
|
4393 |
|
4394 | VisualElementDragControls.prototype.start = function (originEvent, _a) {
|
4395 | var _this = this;
|
4396 | var _b = _a === void 0 ? {} : _a, _c = _b.snapToCursor, snapToCursor = _c === void 0 ? false : _c, cursorProgress = _b.cursorProgress;
|
4397 | |
4398 |
|
4399 |
|
4400 |
|
4401 |
|
4402 | snapToCursor && this.snapToCursor(originEvent);
|
4403 | var onSessionStart = function () {
|
4404 |
|
4405 |
|
4406 |
|
4407 |
|
4408 |
|
4409 |
|
4410 | blockViewportScroll();
|
4411 |
|
4412 |
|
4413 | _this.stopMotion();
|
4414 | };
|
4415 | var onStart = function (event, info) {
|
4416 | var _a, _b;
|
4417 |
|
4418 | var _c = _this.props, drag = _c.drag, dragPropagation = _c.dragPropagation;
|
4419 | if (drag && !dragPropagation) {
|
4420 | if (_this.openGlobalLock)
|
4421 | _this.openGlobalLock();
|
4422 | _this.openGlobalLock = getGlobalLock(drag);
|
4423 |
|
4424 | if (!_this.openGlobalLock)
|
4425 | return;
|
4426 | }
|
4427 | |
4428 |
|
4429 |
|
4430 |
|
4431 |
|
4432 |
|
4433 | _this.prepareBoundingBox();
|
4434 | _this.visualElement.lockTargetBox();
|
4435 | |
4436 |
|
4437 |
|
4438 |
|
4439 |
|
4440 | _this.resolveDragConstraints();
|
4441 | |
4442 |
|
4443 |
|
4444 |
|
4445 |
|
4446 |
|
4447 |
|
4448 |
|
4449 |
|
4450 |
|
4451 |
|
4452 | var point = getViewportPointFromEvent(event).point;
|
4453 | eachAxis(function (axis) {
|
4454 | var _a = _this.visualElement.targetBox[axis], min = _a.min, max = _a.max;
|
4455 | _this.cursorProgress[axis] = cursorProgress
|
4456 | ? cursorProgress[axis]
|
4457 | : progress(min, max, point[axis]);
|
4458 | });
|
4459 |
|
4460 | _this.isDragging = true;
|
4461 | _this.currentDirection = null;
|
4462 |
|
4463 | (_b = (_a = _this.props).onDragStart) === null || _b === void 0 ? void 0 : _b.call(_a, event, info);
|
4464 | };
|
4465 | var onMove = function (event, info) {
|
4466 | var _a, _b, _c, _d;
|
4467 | var _e = _this.props, dragPropagation = _e.dragPropagation, dragDirectionLock = _e.dragDirectionLock;
|
4468 |
|
4469 | if (!dragPropagation && !_this.openGlobalLock)
|
4470 | return;
|
4471 | var offset = info.offset;
|
4472 |
|
4473 | if (dragDirectionLock && _this.currentDirection === null) {
|
4474 | _this.currentDirection = getCurrentDirection(offset);
|
4475 |
|
4476 | if (_this.currentDirection !== null) {
|
4477 | (_b = (_a = _this.props).onDirectionLock) === null || _b === void 0 ? void 0 : _b.call(_a, _this.currentDirection);
|
4478 | }
|
4479 | return;
|
4480 | }
|
4481 |
|
4482 | _this.updateAxis("x", event);
|
4483 | _this.updateAxis("y", event);
|
4484 |
|
4485 | (_d = (_c = _this.props).onDrag) === null || _d === void 0 ? void 0 : _d.call(_c, event, info);
|
4486 |
|
4487 | lastPointerEvent = event;
|
4488 | };
|
4489 | var onEnd = function (event, info) { return _this.stop(event, info); };
|
4490 | var transformPagePoint = this.props.transformPagePoint;
|
4491 | this.panSession = new PanSession(originEvent, {
|
4492 | onSessionStart: onSessionStart,
|
4493 | onStart: onStart,
|
4494 | onMove: onMove,
|
4495 | onEnd: onEnd,
|
4496 | }, { transformPagePoint: transformPagePoint });
|
4497 | };
|
4498 | |
4499 |
|
4500 |
|
4501 | VisualElementDragControls.prototype.prepareBoundingBox = function () {
|
4502 | var element = this.visualElement.getInstance();
|
4503 | var transform = element.style.transform;
|
4504 | this.visualElement.resetTransform();
|
4505 | this.visualElement.measureLayout();
|
4506 | element.style.transform = transform;
|
4507 | this.visualElement.refreshTargetBox();
|
4508 | };
|
4509 | VisualElementDragControls.prototype.resolveDragConstraints = function () {
|
4510 | var dragConstraints = this.props.dragConstraints;
|
4511 | if (dragConstraints) {
|
4512 | this.constraints = isRefObject(dragConstraints)
|
4513 | ? this.resolveRefConstraints(this.visualElement.box, dragConstraints)
|
4514 | : calcRelativeConstraints(this.visualElement.box, dragConstraints);
|
4515 | }
|
4516 | else {
|
4517 | this.constraints = false;
|
4518 | }
|
4519 | };
|
4520 | VisualElementDragControls.prototype.resolveRefConstraints = function (layoutBox, constraints) {
|
4521 | var _a = this.props, onMeasureDragConstraints = _a.onMeasureDragConstraints, transformPagePoint = _a.transformPagePoint;
|
4522 | var constraintsElement = constraints.current;
|
4523 | invariant(constraintsElement !== null, "If `dragConstraints` is set as a React ref, that ref must be passed to another component's `ref` prop.");
|
4524 | this.constraintsBox = getBoundingBox(constraintsElement, transformPagePoint);
|
4525 | var measuredConstraints = calcViewportConstraints(layoutBox, this.constraintsBox);
|
4526 | |
4527 |
|
4528 |
|
4529 |
|
4530 | if (onMeasureDragConstraints) {
|
4531 | var userConstraints = onMeasureDragConstraints(convertAxisBoxToBoundingBox(measuredConstraints));
|
4532 | if (userConstraints) {
|
4533 | measuredConstraints = convertBoundingBoxToAxisBox(userConstraints);
|
4534 | }
|
4535 | }
|
4536 | return measuredConstraints;
|
4537 | };
|
4538 | VisualElementDragControls.prototype.cancelDrag = function () {
|
4539 | unblockViewportScroll();
|
4540 | this.isDragging = false;
|
4541 | this.panSession && this.panSession.end();
|
4542 | this.panSession = null;
|
4543 | if (!this.props.dragPropagation && this.openGlobalLock) {
|
4544 | this.openGlobalLock();
|
4545 | this.openGlobalLock = null;
|
4546 | }
|
4547 | };
|
4548 | VisualElementDragControls.prototype.stop = function (event, info) {
|
4549 | var _a;
|
4550 | this.visualElement.unlockTargetBox();
|
4551 | (_a = this.panSession) === null || _a === void 0 ? void 0 : _a.end();
|
4552 | this.panSession = null;
|
4553 | var isDragging = this.isDragging;
|
4554 | this.cancelDrag();
|
4555 | if (!isDragging)
|
4556 | return;
|
4557 | var _b = this.props, dragMomentum = _b.dragMomentum, dragElastic = _b.dragElastic, onDragEnd = _b.onDragEnd;
|
4558 | if (dragMomentum || dragElastic) {
|
4559 | var velocity = info.velocity;
|
4560 | this.animateDragEnd(velocity);
|
4561 | }
|
4562 | onDragEnd === null || onDragEnd === void 0 ? void 0 : onDragEnd(event, info);
|
4563 | };
|
4564 | VisualElementDragControls.prototype.snapToCursor = function (event) {
|
4565 | this.prepareBoundingBox();
|
4566 | this.cursorProgress.x = 0.5;
|
4567 | this.cursorProgress.y = 0.5;
|
4568 | this.updateAxis("x", event);
|
4569 | this.updateAxis("y", event);
|
4570 | };
|
4571 | |
4572 |
|
4573 |
|
4574 | VisualElementDragControls.prototype.updateAxis = function (axis, event) {
|
4575 | var _a;
|
4576 | var _b = this.props, drag = _b.drag, dragElastic = _b.dragElastic;
|
4577 |
|
4578 | if (!shouldDrag(axis, drag, this.currentDirection))
|
4579 | return;
|
4580 |
|
4581 | var axisLayout = this.visualElement.box[axis];
|
4582 |
|
4583 |
|
4584 | var axisLength = axisLayout.max - axisLayout.min;
|
4585 |
|
4586 | var axisProgress = this.cursorProgress[axis];
|
4587 | var point = getViewportPointFromEvent(event).point;
|
4588 |
|
4589 | var min = calcConstrainedMinPoint(point[axis], axisLength, axisProgress, (_a = this.constraints) === null || _a === void 0 ? void 0 : _a[axis], dragElastic);
|
4590 |
|
4591 | this.visualElement.setAxisTarget(axis, min, min + axisLength);
|
4592 | };
|
4593 | VisualElementDragControls.prototype.updateProps = function (_a) {
|
4594 | var _b = _a.drag, drag = _b === void 0 ? false : _b, _c = _a.dragDirectionLock, dragDirectionLock = _c === void 0 ? false : _c, _d = _a.dragPropagation, dragPropagation = _d === void 0 ? false : _d, _e = _a.dragConstraints, dragConstraints = _e === void 0 ? false : _e, _f = _a.dragElastic, dragElastic = _f === void 0 ? 0.35 : _f, _g = _a.dragMomentum, dragMomentum = _g === void 0 ? true : _g, remainingProps = __rest(_a, ["drag", "dragDirectionLock", "dragPropagation", "dragConstraints", "dragElastic", "dragMomentum"]);
|
4595 | this.props = __assign({ drag: drag,
|
4596 | dragDirectionLock: dragDirectionLock,
|
4597 | dragPropagation: dragPropagation,
|
4598 | dragConstraints: dragConstraints,
|
4599 | dragElastic: dragElastic,
|
4600 | dragMomentum: dragMomentum }, remainingProps);
|
4601 | };
|
4602 | VisualElementDragControls.prototype.animateDragEnd = function (velocity) {
|
4603 | var _this = this;
|
4604 | var _a = this.props, drag = _a.drag, dragMomentum = _a.dragMomentum, dragElastic = _a.dragElastic, dragTransition = _a.dragTransition;
|
4605 | var momentumAnimations = eachAxis(function (axis) {
|
4606 | if (!shouldDrag(axis, drag, _this.currentDirection)) {
|
4607 | return;
|
4608 | }
|
4609 | var transition = _this.constraints ? _this.constraints[axis] : {};
|
4610 | |
4611 |
|
4612 |
|
4613 |
|
4614 |
|
4615 |
|
4616 | var bounceStiffness = dragElastic ? 200 : 1000000;
|
4617 | var bounceDamping = dragElastic ? 40 : 10000000;
|
4618 | var inertia = __assign(__assign({ type: "inertia", velocity: dragMomentum ? velocity[axis] : 0, bounceStiffness: bounceStiffness,
|
4619 | bounceDamping: bounceDamping, timeConstant: 750, restDelta: 1, restSpeed: 10 }, dragTransition), transition);
|
4620 |
|
4621 |
|
4622 |
|
4623 | return _this.visualElement.startLayoutAxisAnimation(axis, inertia);
|
4624 | });
|
4625 |
|
4626 | return Promise.all(momentumAnimations).then(function () {
|
4627 | var _a, _b;
|
4628 | (_b = (_a = _this.props).onDragTransitionEnd) === null || _b === void 0 ? void 0 : _b.call(_a);
|
4629 | });
|
4630 | };
|
4631 | VisualElementDragControls.prototype.stopMotion = function () {
|
4632 | this.visualElement.stopLayoutAnimation();
|
4633 | };
|
4634 | VisualElementDragControls.prototype.scalePoint = function () {
|
4635 | var _this = this;
|
4636 | var _a = this.props, drag = _a.drag, dragConstraints = _a.dragConstraints;
|
4637 | if (!isRefObject(dragConstraints) || !this.constraintsBox)
|
4638 | return;
|
4639 |
|
4640 | this.stopMotion();
|
4641 |
|
4642 | var boxProgress = { x: 0, y: 0 };
|
4643 | eachAxis(function (axis) {
|
4644 | boxProgress[axis] = calcOrigin(_this.visualElement.targetBox[axis], _this.constraintsBox[axis]);
|
4645 | });
|
4646 | |
4647 |
|
4648 |
|
4649 |
|
4650 |
|
4651 | this.prepareBoundingBox();
|
4652 | this.resolveDragConstraints();
|
4653 | eachAxis(function (axis) {
|
4654 | if (!shouldDrag(axis, drag, null))
|
4655 | return;
|
4656 |
|
4657 |
|
4658 | var _a = calcPositionFromProgress(_this.visualElement.targetBox[axis], _this.constraintsBox[axis], boxProgress[axis]), min = _a.min, max = _a.max;
|
4659 | _this.visualElement.setAxisTarget(axis, min, max);
|
4660 | });
|
4661 | };
|
4662 | VisualElementDragControls.prototype.mount = function (visualElement) {
|
4663 | var _this = this;
|
4664 | var element = visualElement.getInstance();
|
4665 | |
4666 |
|
4667 |
|
4668 | var stopPointerListener = addPointerEvent(element, "pointerdown", function (event) {
|
4669 | var _a = _this.props, drag = _a.drag, _b = _a.dragListener, dragListener = _b === void 0 ? true : _b;
|
4670 | drag && dragListener && _this.start(event);
|
4671 | });
|
4672 | |
4673 |
|
4674 |
|
4675 |
|
4676 | var stopResizeListener = addDomEvent(window, "resize", function () {
|
4677 | _this.scalePoint();
|
4678 | });
|
4679 | |
4680 |
|
4681 |
|
4682 |
|
4683 | var stopLayoutUpdateListener = visualElement.onLayoutUpdate(function () {
|
4684 | if (_this.isDragging)
|
4685 | _this.resolveDragConstraints();
|
4686 | });
|
4687 | |
4688 |
|
4689 |
|
4690 |
|
4691 | var prevSnapshot = visualElement.prevSnapshot;
|
4692 | (prevSnapshot === null || prevSnapshot === void 0 ? void 0 : prevSnapshot.isDragging) &&
|
4693 | this.start(lastPointerEvent, {
|
4694 | cursorProgress: prevSnapshot.cursorProgress,
|
4695 | });
|
4696 | |
4697 |
|
4698 |
|
4699 | return function () {
|
4700 | stopPointerListener === null || stopPointerListener === void 0 ? void 0 : stopPointerListener();
|
4701 | stopResizeListener === null || stopResizeListener === void 0 ? void 0 : stopResizeListener();
|
4702 | stopLayoutUpdateListener === null || stopLayoutUpdateListener === void 0 ? void 0 : stopLayoutUpdateListener();
|
4703 | _this.cancelDrag();
|
4704 | };
|
4705 | };
|
4706 | return VisualElementDragControls;
|
4707 | }());
|
4708 | function shouldDrag(direction, drag, currentDirection) {
|
4709 | return ((drag === true || drag === direction) &&
|
4710 | (currentDirection === null || currentDirection === direction));
|
4711 | }
|
4712 |
|
4713 |
|
4714 |
|
4715 |
|
4716 |
|
4717 |
|
4718 |
|
4719 | function getCurrentDirection(offset, lockThreshold) {
|
4720 | if (lockThreshold === void 0) { lockThreshold = 10; }
|
4721 | var direction = null;
|
4722 | if (Math.abs(offset.y) > lockThreshold) {
|
4723 | direction = "y";
|
4724 | }
|
4725 | else if (Math.abs(offset.x) > lockThreshold) {
|
4726 | direction = "x";
|
4727 | }
|
4728 | return direction;
|
4729 | }
|
4730 |
|
4731 |
|
4732 |
|
4733 |
|
4734 |
|
4735 |
|
4736 | function useDrag(props, visualElement) {
|
4737 | var groupDragControls = props.dragControls;
|
4738 | var transformPagePoint = useContext(MotionConfigContext).transformPagePoint;
|
4739 | var dragControls = useConstant(function () {
|
4740 | return new VisualElementDragControls({
|
4741 | visualElement: visualElement,
|
4742 | });
|
4743 | });
|
4744 | dragControls.updateProps(__assign(__assign({}, props), { transformPagePoint: transformPagePoint }));
|
4745 |
|
4746 |
|
4747 | useEffect(function () { return groupDragControls && groupDragControls.subscribe(dragControls); }, [dragControls]);
|
4748 |
|
4749 | useEffect(function () { return dragControls.mount(visualElement); }, []);
|
4750 | }
|
4751 |
|
4752 | var makeRenderlessComponent = function (hook) { return function (props) {
|
4753 | hook(props);
|
4754 | return null;
|
4755 | }; };
|
4756 |
|
4757 | var Component = makeRenderlessComponent(function (_a) {
|
4758 | var visualElement = _a.visualElement, props = __rest(_a, ["visualElement"]);
|
4759 | return useDrag(props, visualElement);
|
4760 | });
|
4761 |
|
4762 |
|
4763 |
|
4764 | var Drag = {
|
4765 | key: "drag",
|
4766 | shouldRender: function (props) { return !!props.drag; },
|
4767 | getComponent: function () { return Component; },
|
4768 | };
|
4769 |
|
4770 |
|
4771 |
|
4772 |
|
4773 |
|
4774 |
|
4775 |
|
4776 |
|
4777 |
|
4778 |
|
4779 |
|
4780 |
|
4781 |
|
4782 | function usePanGesture(_a, ref) {
|
4783 | var onPan = _a.onPan, onPanStart = _a.onPanStart, onPanEnd = _a.onPanEnd, onPanSessionStart = _a.onPanSessionStart;
|
4784 | var hasPanEvents = onPan || onPanStart || onPanEnd || onPanSessionStart;
|
4785 | var panSession = useRef(null);
|
4786 | var transformPagePoint = useContext(MotionConfigContext).transformPagePoint;
|
4787 | var handlers = {
|
4788 | onSessionStart: onPanSessionStart,
|
4789 | onStart: onPanStart,
|
4790 | onMove: onPan,
|
4791 | onEnd: function (event, info) {
|
4792 | panSession.current = null;
|
4793 | onPanEnd && onPanEnd(event, info);
|
4794 | },
|
4795 | };
|
4796 | useEffect(function () {
|
4797 | if (panSession.current !== null) {
|
4798 | panSession.current.updateHandlers(handlers);
|
4799 | }
|
4800 | });
|
4801 | function onPointerDown(event) {
|
4802 | panSession.current = new PanSession(event, handlers, {
|
4803 | transformPagePoint: transformPagePoint,
|
4804 | });
|
4805 | }
|
4806 | usePointerEvent(ref, "pointerdown", hasPanEvents && onPointerDown);
|
4807 | useUnmountEffect(function () { return panSession.current && panSession.current.end(); });
|
4808 | }
|
4809 |
|
4810 |
|
4811 |
|
4812 |
|
4813 |
|
4814 |
|
4815 |
|
4816 |
|
4817 | var isNodeOrChild = function (parent, child) {
|
4818 | if (!child) {
|
4819 | return false;
|
4820 | }
|
4821 | else if (parent === child) {
|
4822 | return true;
|
4823 | }
|
4824 | else {
|
4825 | return isNodeOrChild(parent, child.parentElement);
|
4826 | }
|
4827 | };
|
4828 |
|
4829 | var order$1 = ["whileHover", "whileTap", "whileDrag"];
|
4830 | var getGesturePriority = function (gesture) {
|
4831 | return order$1.indexOf(gesture) + 1;
|
4832 | };
|
4833 |
|
4834 | var tapGesturePriority = getGesturePriority("whileTap");
|
4835 |
|
4836 |
|
4837 |
|
4838 |
|
4839 | function useTapGesture(_a, ref) {
|
4840 | var onTap = _a.onTap, onTapStart = _a.onTapStart, onTapCancel = _a.onTapCancel, whileTap = _a.whileTap, controls = _a.controls;
|
4841 | var hasTapListeners = onTap || onTapStart || onTapCancel || whileTap;
|
4842 | var isTapping = useRef(false);
|
4843 | var cancelPointerEventListener = useRef(null);
|
4844 | function removePointerUp() {
|
4845 | cancelPointerEventListener.current &&
|
4846 | cancelPointerEventListener.current();
|
4847 | cancelPointerEventListener.current = null;
|
4848 | }
|
4849 | if (whileTap && controls) {
|
4850 | controls.setOverride(whileTap, tapGesturePriority);
|
4851 | }
|
4852 |
|
4853 |
|
4854 | var onPointerUp = useRef(null);
|
4855 | onPointerUp.current = function (event, info) {
|
4856 | var element = ref.current;
|
4857 | removePointerUp();
|
4858 | if (!isTapping.current || !element)
|
4859 | return;
|
4860 | isTapping.current = false;
|
4861 | if (controls && whileTap) {
|
4862 | controls.clearOverride(tapGesturePriority);
|
4863 | }
|
4864 |
|
4865 |
|
4866 | var openGestureLock = getGlobalLock(true);
|
4867 | if (!openGestureLock)
|
4868 | return;
|
4869 | openGestureLock();
|
4870 | if (!isNodeOrChild(element, event.target)) {
|
4871 | onTapCancel && onTapCancel(event, info);
|
4872 | }
|
4873 | else {
|
4874 | onTap && onTap(event, info);
|
4875 | }
|
4876 | };
|
4877 | function onPointerDown(event, info) {
|
4878 | removePointerUp();
|
4879 | cancelPointerEventListener.current = addPointerEvent(window, "pointerup", function (event, info) { return onPointerUp.current(event, info); });
|
4880 | var element = ref.current;
|
4881 | if (!element || isTapping.current)
|
4882 | return;
|
4883 | isTapping.current = true;
|
4884 | onTapStart && onTapStart(event, info);
|
4885 | if (controls && whileTap) {
|
4886 | controls.startOverride(tapGesturePriority);
|
4887 | }
|
4888 | }
|
4889 | usePointerEvent(ref, "pointerdown", hasTapListeners ? onPointerDown : undefined);
|
4890 | useUnmountEffect(removePointerUp);
|
4891 | }
|
4892 |
|
4893 | var hoverPriority = getGesturePriority("whileHover");
|
4894 | var filterTouch = function (listener) { return function (event, info) {
|
4895 | if (isMouseEvent(event))
|
4896 | listener(event, info);
|
4897 | }; };
|
4898 |
|
4899 |
|
4900 |
|
4901 |
|
4902 |
|
4903 |
|
4904 | function useHoverGesture(_a, ref) {
|
4905 | var whileHover = _a.whileHover, onHoverStart = _a.onHoverStart, onHoverEnd = _a.onHoverEnd, controls = _a.controls;
|
4906 | if (whileHover && controls) {
|
4907 | controls.setOverride(whileHover, hoverPriority);
|
4908 | }
|
4909 | usePointerEvent(ref, "pointerenter", filterTouch(function (event, info) {
|
4910 | if (onHoverStart)
|
4911 | onHoverStart(event, info);
|
4912 | if (whileHover && controls) {
|
4913 | controls.startOverride(hoverPriority);
|
4914 | }
|
4915 | }));
|
4916 | usePointerEvent(ref, "pointerleave", filterTouch(function (event, info) {
|
4917 | if (onHoverEnd)
|
4918 | onHoverEnd(event, info);
|
4919 | if (whileHover && controls) {
|
4920 | controls.clearOverride(hoverPriority);
|
4921 | }
|
4922 | }));
|
4923 | }
|
4924 |
|
4925 |
|
4926 |
|
4927 |
|
4928 |
|
4929 |
|
4930 |
|
4931 |
|
4932 | function useGestures(props, ref) {
|
4933 | usePanGesture(props, ref);
|
4934 | useTapGesture(props, ref);
|
4935 | useHoverGesture(props, ref);
|
4936 | }
|
4937 |
|
4938 | var gestureProps = [
|
4939 | "onPan",
|
4940 | "onPanStart",
|
4941 | "onPanEnd",
|
4942 | "onPanSessionStart",
|
4943 | "onTap",
|
4944 | "onTapStart",
|
4945 | "onTapCancel",
|
4946 | "whileTap",
|
4947 | "whileHover",
|
4948 | "onHoverStart",
|
4949 | "onHoverEnd",
|
4950 | ];
|
4951 | var GestureComponent = makeRenderlessComponent(function (_a) {
|
4952 | var visualElement = _a.visualElement, props = __rest(_a, ["visualElement"]);
|
4953 | useGestures(props, visualElement);
|
4954 | });
|
4955 |
|
4956 |
|
4957 |
|
4958 | var Gestures = {
|
4959 | key: "gestures",
|
4960 | shouldRender: function (props) {
|
4961 | return gestureProps.some(function (key) { return props.hasOwnProperty(key); });
|
4962 | },
|
4963 | getComponent: function () { return GestureComponent; },
|
4964 | };
|
4965 |
|
4966 | var ExitComponent = makeRenderlessComponent(function (props) {
|
4967 | var animate = props.animate, controls = props.controls, exit = props.exit;
|
4968 | var _a = usePresence(), isPresent = _a[0], onExitComplete = _a[1];
|
4969 | var presenceContext = useContext(PresenceContext);
|
4970 | var isPlayingExitAnimation = useRef(false);
|
4971 | var custom = (presenceContext === null || presenceContext === void 0 ? void 0 : presenceContext.custom) !== undefined
|
4972 | ? presenceContext.custom
|
4973 | : props.custom;
|
4974 | useEffect(function () {
|
4975 | if (!isPresent) {
|
4976 | if (!isPlayingExitAnimation.current && exit) {
|
4977 | controls.setProps(__assign(__assign({}, props), { custom: custom }));
|
4978 | controls.start(exit).then(onExitComplete);
|
4979 | }
|
4980 | isPlayingExitAnimation.current = true;
|
4981 | }
|
4982 | else if (isPlayingExitAnimation.current &&
|
4983 | animate &&
|
4984 | typeof animate !== "boolean" &&
|
4985 | !(animate instanceof AnimationControls)) {
|
4986 | controls.start(animate);
|
4987 | }
|
4988 | if (isPresent) {
|
4989 | isPlayingExitAnimation.current = false;
|
4990 | }
|
4991 | }, [animate, controls, custom, exit, isPresent, onExitComplete, props]);
|
4992 | });
|
4993 |
|
4994 |
|
4995 |
|
4996 | var Exit = {
|
4997 | key: "exit",
|
4998 | shouldRender: function (props) { return !!props.exit && !checkShouldInheritVariant(props); },
|
4999 | getComponent: function () { return ExitComponent; },
|
5000 | };
|
5001 |
|
5002 | var AnimatePropType;
|
5003 | (function (AnimatePropType) {
|
5004 | AnimatePropType["Target"] = "Target";
|
5005 | AnimatePropType["VariantLabel"] = "VariantLabel";
|
5006 | AnimatePropType["AnimationSubscription"] = "AnimationSubscription";
|
5007 | })(AnimatePropType || (AnimatePropType = {}));
|
5008 |
|
5009 | function shallowCompare(next, prev) {
|
5010 | if (prev === null)
|
5011 | return false;
|
5012 | var prevLength = prev.length;
|
5013 | if (prevLength !== next.length)
|
5014 | return false;
|
5015 | for (var i = 0; i < prevLength; i++) {
|
5016 | if (prev[i] !== next[i])
|
5017 | return false;
|
5018 | }
|
5019 | return true;
|
5020 | }
|
5021 |
|
5022 | var hasUpdated = function (prev, next) {
|
5023 | return (next !== undefined &&
|
5024 | (Array.isArray(prev) && Array.isArray(next)
|
5025 | ? !shallowCompare(next, prev)
|
5026 | : prev !== next));
|
5027 | };
|
5028 | function targetWithoutTransition(_a, mergeTransitionEnd) {
|
5029 | if (mergeTransitionEnd === void 0) { mergeTransitionEnd = false; }
|
5030 | var transition = _a.transition, transitionEnd = _a.transitionEnd, target = __rest(_a, ["transition", "transitionEnd"]);
|
5031 | return mergeTransitionEnd
|
5032 | ? __assign(__assign({}, target), transitionEnd)
|
5033 | : target;
|
5034 | }
|
5035 |
|
5036 |
|
5037 |
|
5038 |
|
5039 |
|
5040 |
|
5041 |
|
5042 |
|
5043 |
|
5044 |
|
5045 |
|
5046 |
|
5047 |
|
5048 |
|
5049 |
|
5050 |
|
5051 |
|
5052 |
|
5053 |
|
5054 |
|
5055 |
|
5056 | function useAnimateProp(targetAndTransition, controls, visualElement, defaultTransition) {
|
5057 | var isInitialRender = useRef(true);
|
5058 | var prevValues = useRef(null);
|
5059 | if (!prevValues.current) {
|
5060 | prevValues.current = targetWithoutTransition(targetAndTransition, true);
|
5061 | }
|
5062 | useEffect(function () {
|
5063 | var targetToAnimate = {};
|
5064 |
|
5065 | var animatingTarget = targetWithoutTransition(targetAndTransition);
|
5066 |
|
5067 | var finalTarget = targetWithoutTransition(targetAndTransition, true);
|
5068 |
|
5069 | for (var key in animatingTarget) {
|
5070 |
|
5071 |
|
5072 | var shouldAnimateOnMount = isInitialRender.current &&
|
5073 | (!visualElement.hasValue(key) ||
|
5074 | visualElement.getValue(key).get() !== finalTarget[key]);
|
5075 |
|
5076 |
|
5077 | var isValidValue = finalTarget[key] !== null;
|
5078 | var valueHasUpdated = hasUpdated(prevValues.current[key], finalTarget[key]);
|
5079 | if (isValidValue && (valueHasUpdated || shouldAnimateOnMount)) {
|
5080 | targetToAnimate[key] = animatingTarget[key];
|
5081 | }
|
5082 | }
|
5083 | isInitialRender.current = false;
|
5084 | prevValues.current = __assign(__assign({}, prevValues.current), finalTarget);
|
5085 | if (Object.keys(targetToAnimate).length) {
|
5086 | controls.start(__assign(__assign({}, targetToAnimate), { transition: targetAndTransition.transition || defaultTransition, transitionEnd: targetAndTransition.transitionEnd }));
|
5087 | }
|
5088 | }, [targetAndTransition]);
|
5089 | }
|
5090 |
|
5091 | var labelsToArray = function (label) {
|
5092 | if (!label) {
|
5093 | return [];
|
5094 | }
|
5095 | if (Array.isArray(label)) {
|
5096 | return label;
|
5097 | }
|
5098 | return [label];
|
5099 | };
|
5100 | var resolveVariantLabels = function (variant) {
|
5101 | var unresolvedVariant = variant instanceof MotionValue ? variant.get() : variant;
|
5102 | return Array.from(new Set(labelsToArray(unresolvedVariant)));
|
5103 | };
|
5104 |
|
5105 |
|
5106 |
|
5107 |
|
5108 |
|
5109 | var asDependencyList = function (list) { return [
|
5110 | list.join(","),
|
5111 | ]; };
|
5112 |
|
5113 | var hasVariantChanged = function (oldVariant, newVariant) {
|
5114 | return oldVariant.join(",") !== newVariant.join(",");
|
5115 | };
|
5116 |
|
5117 |
|
5118 |
|
5119 |
|
5120 |
|
5121 |
|
5122 |
|
5123 |
|
5124 |
|
5125 |
|
5126 | function useVariants(initial, animate, inherit, controls) {
|
5127 | var targetVariants = resolveVariantLabels(animate);
|
5128 | var context = useContext(MotionContext);
|
5129 | var parentAlreadyMounted = context.hasMounted && context.hasMounted.current;
|
5130 | var hasMounted = useRef(false);
|
5131 | useEffect(function () {
|
5132 | var shouldAnimate = false;
|
5133 | if (inherit) {
|
5134 |
|
5135 |
|
5136 |
|
5137 | shouldAnimate = !!parentAlreadyMounted;
|
5138 | targetVariants = resolveVariantLabels(context.animate);
|
5139 | }
|
5140 | else {
|
5141 | shouldAnimate =
|
5142 | hasMounted.current ||
|
5143 | hasVariantChanged(resolveVariantLabels(initial), targetVariants);
|
5144 | }
|
5145 | shouldAnimate && controls.start(targetVariants);
|
5146 | hasMounted.current = true;
|
5147 | }, asDependencyList(targetVariants));
|
5148 | }
|
5149 |
|
5150 |
|
5151 |
|
5152 |
|
5153 |
|
5154 |
|
5155 |
|
5156 |
|
5157 |
|
5158 |
|
5159 | function useAnimationGroupSubscription(animation, controls) {
|
5160 | var unsubscribe = useMemo(function () { return animation.subscribe(controls); }, [
|
5161 | animation,
|
5162 | ]);
|
5163 | useEffect(function () { return function () {
|
5164 | unsubscribe && unsubscribe();
|
5165 | }; }, [unsubscribe]);
|
5166 | }
|
5167 |
|
5168 | var _a, _b;
|
5169 | var AnimatePropComponents = (_a = {},
|
5170 | _a[AnimatePropType.Target] = makeRenderlessComponent(function (_a) {
|
5171 | var animate = _a.animate, controls = _a.controls, visualElement = _a.visualElement, transition = _a.transition;
|
5172 | return useAnimateProp(animate, controls, visualElement, transition);
|
5173 | }),
|
5174 | _a[AnimatePropType.VariantLabel] = makeRenderlessComponent(function (_a) {
|
5175 | var animate = _a.animate, _b = _a.inherit, inherit = _b === void 0 ? true : _b, controls = _a.controls, initial = _a.initial;
|
5176 | return useVariants(initial, animate, inherit, controls);
|
5177 | }),
|
5178 | _a[AnimatePropType.AnimationSubscription] = makeRenderlessComponent(function (_a) {
|
5179 | var animate = _a.animate, controls = _a.controls;
|
5180 | return useAnimationGroupSubscription(animate, controls);
|
5181 | }),
|
5182 | _a);
|
5183 | var isVariantLabel$1 = function (prop) {
|
5184 | return Array.isArray(prop) || typeof prop === "string";
|
5185 | };
|
5186 | var isAnimationSubscription = function (_a) {
|
5187 | var animate = _a.animate;
|
5188 | return animate instanceof AnimationControls;
|
5189 | };
|
5190 | var animationProps = ["initial", "animate", "whileTap", "whileHover"];
|
5191 | var animatePropTypeTests = (_b = {},
|
5192 | _b[AnimatePropType.Target] = function (props) {
|
5193 | return (props.animate !== undefined &&
|
5194 | !isVariantLabel$1(props.animate) &&
|
5195 | !isAnimationSubscription(props));
|
5196 | },
|
5197 | _b[AnimatePropType.VariantLabel] = function (props) {
|
5198 | return (props.variants !== undefined ||
|
5199 | animationProps.some(function (key) { return typeof props[key] === "string"; }));
|
5200 | },
|
5201 | _b[AnimatePropType.AnimationSubscription] = isAnimationSubscription,
|
5202 | _b);
|
5203 | var getAnimationComponent = function (props) {
|
5204 | var animatePropType = undefined;
|
5205 | for (var key in AnimatePropType) {
|
5206 | if (animatePropTypeTests[key](props)) {
|
5207 | animatePropType = key;
|
5208 | }
|
5209 | }
|
5210 | return animatePropType ? AnimatePropComponents[animatePropType] : undefined;
|
5211 | };
|
5212 |
|
5213 |
|
5214 |
|
5215 | var Animation = {
|
5216 | key: "animation",
|
5217 | shouldRender: function () { return true; },
|
5218 | getComponent: getAnimationComponent,
|
5219 | };
|
5220 |
|
5221 | function tweenAxis(target, prev, next, p) {
|
5222 | target.min = mix(prev.min, next.min, p);
|
5223 | target.max = mix(prev.max, next.max, p);
|
5224 | }
|
5225 |
|
5226 | var progressTarget = 1000;
|
5227 | var Animate = (function (_super) {
|
5228 | __extends(Animate, _super);
|
5229 | function Animate() {
|
5230 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
5231 | _this.frameTarget = {
|
5232 | x: { min: 0, max: 0 },
|
5233 | y: { min: 0, max: 0 },
|
5234 | };
|
5235 | _this.stopAxisAnimation = {
|
5236 | x: undefined,
|
5237 | y: undefined,
|
5238 | };
|
5239 | _this.animate = function (target, origin, _a) {
|
5240 | if (_a === void 0) { _a = {}; }
|
5241 | var originBox = _a.originBox, targetBox = _a.targetBox, visibilityAction = _a.visibilityAction, config = __rest(_a, ["originBox", "targetBox", "visibilityAction"]);
|
5242 | var _b = _this.props, visualElement = _b.visualElement, layout = _b.layout;
|
5243 | |
5244 |
|
5245 |
|
5246 |
|
5247 | origin = originBox || origin;
|
5248 | target = targetBox || target;
|
5249 | var boxHasMoved = hasMoved(origin, target);
|
5250 | var animations = eachAxis(function (axis) {
|
5251 | |
5252 |
|
5253 |
|
5254 |
|
5255 | if (layout === "position") {
|
5256 | var targetLength = target[axis].max - target[axis].min;
|
5257 | origin[axis].max = origin[axis].min + targetLength;
|
5258 | }
|
5259 | if (visualElement.isTargetBoxLocked) {
|
5260 | return;
|
5261 | }
|
5262 | else if (visibilityAction !== undefined) {
|
5263 |
|
5264 | visibilityAction === VisibilityAction.Hide
|
5265 | ? visualElement.hide()
|
5266 | : visualElement.show();
|
5267 | }
|
5268 | else if (boxHasMoved) {
|
5269 |
|
5270 |
|
5271 | return _this.animateAxis(axis, target[axis], origin[axis], config);
|
5272 | }
|
5273 | else {
|
5274 |
|
5275 |
|
5276 | return visualElement.setAxisTarget(axis, target[axis].min, target[axis].max);
|
5277 | }
|
5278 | });
|
5279 |
|
5280 | visualElement.render();
|
5281 | |
5282 |
|
5283 |
|
5284 |
|
5285 |
|
5286 | return Promise.all(animations).then(function () {
|
5287 | var _a, _b;
|
5288 | (_b = (_a = _this.props).onLayoutAnimationComplete) === null || _b === void 0 ? void 0 : _b.call(_a);
|
5289 | if (visualElement.isPresent) {
|
5290 | visualElement.presence = Presence.Present;
|
5291 | }
|
5292 | else {
|
5293 | _this.safeToRemove();
|
5294 | }
|
5295 | });
|
5296 | };
|
5297 | return _this;
|
5298 | }
|
5299 | Animate.prototype.componentDidMount = function () {
|
5300 | var visualElement = this.props.visualElement;
|
5301 | visualElement.enableLayoutProjection();
|
5302 | this.unsubLayoutReady = visualElement.onLayoutUpdate(this.animate);
|
5303 | };
|
5304 | Animate.prototype.componentWillUnmount = function () {
|
5305 | var _this = this;
|
5306 | this.unsubLayoutReady();
|
5307 | eachAxis(function (axis) { var _a, _b; return (_b = (_a = _this.stopAxisAnimation)[axis]) === null || _b === void 0 ? void 0 : _b.call(_a); });
|
5308 | };
|
5309 | |
5310 |
|
5311 |
|
5312 |
|
5313 |
|
5314 | Animate.prototype.animateAxis = function (axis, target, origin, _a) {
|
5315 | var _b, _c;
|
5316 | var _d = _a === void 0 ? {} : _a, transition = _d.transition, crossfadeOpacity = _d.crossfadeOpacity;
|
5317 | (_c = (_b = this.stopAxisAnimation)[axis]) === null || _c === void 0 ? void 0 : _c.call(_b);
|
5318 | var visualElement = this.props.visualElement;
|
5319 | var frameTarget = this.frameTarget[axis];
|
5320 | var layoutProgress = visualElement.axisProgress[axis];
|
5321 | |
5322 |
|
5323 |
|
5324 |
|
5325 | layoutProgress.clearListeners();
|
5326 | layoutProgress.set(0);
|
5327 | layoutProgress.set(0);
|
5328 | |
5329 |
|
5330 |
|
5331 |
|
5332 | var crossfade = crossfadeOpacity && this.createCrossfadeAnimation(crossfadeOpacity);
|
5333 | |
5334 |
|
5335 |
|
5336 |
|
5337 | var frame = function () {
|
5338 |
|
5339 | var p = layoutProgress.get() / progressTarget;
|
5340 |
|
5341 | tweenAxis(frameTarget, origin, target, p);
|
5342 | visualElement.setAxisTarget(axis, frameTarget.min, frameTarget.max);
|
5343 |
|
5344 | crossfade === null || crossfade === void 0 ? void 0 : crossfade(p);
|
5345 | };
|
5346 |
|
5347 | frame();
|
5348 |
|
5349 | var animation = startAnimation(axis === "x" ? "layoutX" : "layoutY", layoutProgress, progressTarget, transition || this.props.transition || defaultTransition);
|
5350 |
|
5351 | var unsubscribeProgress = layoutProgress.onChange(frame);
|
5352 | this.stopAxisAnimation[axis] = function () {
|
5353 | layoutProgress.stop();
|
5354 | unsubscribeProgress();
|
5355 | };
|
5356 | return animation;
|
5357 | };
|
5358 | Animate.prototype.createCrossfadeAnimation = function (crossfadeOpacity) {
|
5359 | var visualElement = this.props.visualElement;
|
5360 | var opacity = visualElement.getValue("opacity", 0);
|
5361 | return function (p) {
|
5362 | opacity.set(easeCrossfadeIn(mix(0, 1, p)));
|
5363 | crossfadeOpacity.set(easeCrossfadeOut(mix(1, 0, p)));
|
5364 | };
|
5365 | };
|
5366 | Animate.prototype.safeToRemove = function () {
|
5367 | var _a, _b;
|
5368 | (_b = (_a = this.props).safeToRemove) === null || _b === void 0 ? void 0 : _b.call(_a);
|
5369 | };
|
5370 | Animate.prototype.render = function () {
|
5371 | return null;
|
5372 | };
|
5373 | return Animate;
|
5374 | }(Component$1));
|
5375 | function AnimateLayoutContextProvider(props) {
|
5376 | var _a = usePresence(), safeToRemove = _a[1];
|
5377 | return createElement(Animate, __assign({}, props, { safeToRemove: safeToRemove }));
|
5378 | }
|
5379 | function hasMoved(a, b) {
|
5380 | return hasAxisMoved(a.x, b.x) || hasAxisMoved(a.y, b.y);
|
5381 | }
|
5382 | function hasAxisMoved(a, b) {
|
5383 | return a.min !== b.min || a.max !== b.max;
|
5384 | }
|
5385 | var defaultTransition = {
|
5386 | duration: 0.45,
|
5387 | ease: [0.4, 0, 0.1, 1],
|
5388 | };
|
5389 | function compress(min, max, easing) {
|
5390 | return function (p) {
|
5391 |
|
5392 | if (p < min)
|
5393 | return 0;
|
5394 | if (p > max)
|
5395 | return 1;
|
5396 | return easing(progress(min, max, p));
|
5397 | };
|
5398 | }
|
5399 | var easeCrossfadeIn = compress(0, 0.5, circOut);
|
5400 | var easeCrossfadeOut = compress(0.5, 0.95, linear$1);
|
5401 |
|
5402 |
|
5403 |
|
5404 | var AnimateLayout = {
|
5405 | key: "animate-layout",
|
5406 | shouldRender: function (props) { return !!props.layout || !!props.layoutId; },
|
5407 | getComponent: function () { return AnimateLayoutContextProvider; },
|
5408 | };
|
5409 |
|
5410 |
|
5411 |
|
5412 |
|
5413 | var Measure = (function (_super) {
|
5414 | __extends(Measure, _super);
|
5415 | function Measure(props) {
|
5416 | var _this = _super.call(this, props) || this;
|
5417 | |
5418 |
|
5419 |
|
5420 |
|
5421 | var syncLayout = props.syncLayout;
|
5422 | if (!isSharedLayout(syncLayout)) {
|
5423 | _this.componentDidUpdate = function () { return syncLayout.flush(); };
|
5424 | }
|
5425 | return _this;
|
5426 | }
|
5427 | |
5428 |
|
5429 |
|
5430 | Measure.prototype.componentDidMount = function () {
|
5431 | var _a = this.props, syncLayout = _a.syncLayout, visualElement = _a.visualElement;
|
5432 | isSharedLayout(syncLayout) && syncLayout.register(visualElement);
|
5433 | };
|
5434 | |
5435 |
|
5436 |
|
5437 |
|
5438 |
|
5439 |
|
5440 | Measure.prototype.getSnapshotBeforeUpdate = function () {
|
5441 | var _a = this.props, syncLayout = _a.syncLayout, visualElement = _a.visualElement;
|
5442 | if (isSharedLayout(syncLayout)) {
|
5443 | syncLayout.syncUpdate();
|
5444 | }
|
5445 | else {
|
5446 | visualElement.snapshotBoundingBox();
|
5447 | syncLayout.add(visualElement);
|
5448 | }
|
5449 | return null;
|
5450 | };
|
5451 | Measure.prototype.componentDidUpdate = function () { };
|
5452 | Measure.prototype.render = function () {
|
5453 | return null;
|
5454 | };
|
5455 | return Measure;
|
5456 | }(React__default.Component));
|
5457 | function MeasureContextProvider(props) {
|
5458 | var syncLayout = useContext(SharedLayoutContext);
|
5459 | return React__default.createElement(Measure, __assign({}, props, { syncLayout: syncLayout }));
|
5460 | }
|
5461 | var MeasureLayout = {
|
5462 | key: "measure-layout",
|
5463 | shouldRender: function (props) {
|
5464 | return !!props.drag || !!props.layout || !!props.layoutId;
|
5465 | },
|
5466 | getComponent: function () { return MeasureContextProvider; },
|
5467 | };
|
5468 |
|
5469 |
|
5470 |
|
5471 |
|
5472 |
|
5473 |
|
5474 |
|
5475 |
|
5476 |
|
5477 |
|
5478 |
|
5479 |
|
5480 |
|
5481 |
|
5482 |
|
5483 | function createMotionProxy(defaultFeatures) {
|
5484 | var config = {
|
5485 | defaultFeatures: defaultFeatures,
|
5486 | useVisualElement: useDomVisualElement,
|
5487 | render: render,
|
5488 | animationControlsConfig: {
|
5489 | makeTargetAnimatable: parseDomVariant,
|
5490 | },
|
5491 | };
|
5492 | function custom(Component) {
|
5493 | return createMotionComponent(Component, config);
|
5494 | }
|
5495 | var componentCache = new Map();
|
5496 | function get(target, key) {
|
5497 | if (key === "custom")
|
5498 | return target.custom;
|
5499 | if (!componentCache.has(key)) {
|
5500 | componentCache.set(key, createMotionComponent(key, config));
|
5501 | }
|
5502 | return componentCache.get(key);
|
5503 | }
|
5504 | return new Proxy({ custom: custom }, { get: get });
|
5505 | }
|
5506 | /**
|
5507 | * HTML & SVG components, optimised for use with gestures and animation. These can be used as
|
5508 | * drop-in replacements for any HTML & SVG component, all CSS & SVG properties are supported.
|
5509 | *
|
5510 | * @public
|
5511 | */
|
5512 | var motion = /*@__PURE__*/ createMotionProxy([
|
5513 | MeasureLayout,
|
5514 | Animation,
|
5515 | Drag,
|
5516 | Gestures,
|
5517 | Exit,
|
5518 | AnimateLayout,
|
5519 | ]);
|
5520 | /**
|
5521 | * @public
|
5522 | */
|
5523 | var m = /*@__PURE__*/ createMotionProxy([MeasureLayout]);
|
5524 |
|
5525 | function useForceUpdate() {
|
5526 | var _a = useState(0), forcedRenderCount = _a[0], setForcedRenderCount = _a[1];
|
5527 | return useCallback(function () { return setForcedRenderCount(forcedRenderCount + 1); }, [
|
5528 | forcedRenderCount,
|
5529 | ]);
|
5530 | }
|
5531 |
|
5532 | var presenceId = 0;
|
5533 | function getPresenceId() {
|
5534 | var id = presenceId;
|
5535 | presenceId++;
|
5536 | return id;
|
5537 | }
|
5538 | var PresenceChild = function (_a) {
|
5539 | var children = _a.children, initial = _a.initial, isPresent = _a.isPresent, onExitComplete = _a.onExitComplete, custom = _a.custom;
|
5540 | var presenceChildren = useConstant(newChildrenMap);
|
5541 | var context = {
|
5542 | id: useConstant(getPresenceId),
|
5543 | initial: initial,
|
5544 | isPresent: isPresent,
|
5545 | custom: custom,
|
5546 | onExitComplete: function (childId) {
|
5547 | presenceChildren.set(childId, true);
|
5548 | var allComplete = true;
|
5549 | presenceChildren.forEach(function (isComplete) {
|
5550 | if (!isComplete)
|
5551 | allComplete = false;
|
5552 | });
|
5553 | allComplete && (onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete());
|
5554 | },
|
5555 | register: function (childId) {
|
5556 | presenceChildren.set(childId, false);
|
5557 | return function () { return presenceChildren.delete(childId); };
|
5558 | },
|
5559 | };
|
5560 | useMemo(function () {
|
5561 | presenceChildren.forEach(function (_, key) { return presenceChildren.set(key, false); });
|
5562 | }, [isPresent]);
|
5563 | return (createElement(PresenceContext.Provider, { value: context }, children));
|
5564 | };
|
5565 | function newChildrenMap() {
|
5566 | return new Map();
|
5567 | }
|
5568 |
|
5569 | function getChildKey(child) {
|
5570 | return child.key || "";
|
5571 | }
|
5572 | function updateChildLookup(children, allChildren) {
|
5573 | var seenChildren = process.env.NODE_ENV !== "production" ? new Set() : null;
|
5574 | children.forEach(function (child) {
|
5575 | var key = getChildKey(child);
|
5576 | if (process.env.NODE_ENV !== "production" && seenChildren) {
|
5577 | if (seenChildren.has(key)) {
|
5578 | console.warn("Children of AnimatePresence require unique keys. \"" + key + "\" is a duplicate.");
|
5579 | }
|
5580 | seenChildren.add(key);
|
5581 | }
|
5582 | allChildren.set(key, child);
|
5583 | });
|
5584 | }
|
5585 | function onlyElements(children) {
|
5586 | var filtered = [];
|
5587 |
|
5588 | Children.forEach(children, function (child) {
|
5589 | if (isValidElement(child))
|
5590 | filtered.push(child);
|
5591 | });
|
5592 | return filtered;
|
5593 | }
|
5594 |
|
5595 |
|
5596 |
|
5597 |
|
5598 |
|
5599 |
|
5600 |
|
5601 |
|
5602 |
|
5603 |
|
5604 |
|
5605 |
|
5606 |
|
5607 |
|
5608 |
|
5609 |
|
5610 |
|
5611 |
|
5612 |
|
5613 |
|
5614 |
|
5615 |
|
5616 |
|
5617 |
|
5618 |
|
5619 |
|
5620 |
|
5621 |
|
5622 |
|
5623 |
|
5624 |
|
5625 |
|
5626 |
|
5627 |
|
5628 |
|
5629 |
|
5630 |
|
5631 |
|
5632 |
|
5633 |
|
5634 |
|
5635 |
|
5636 |
|
5637 |
|
5638 |
|
5639 |
|
5640 |
|
5641 |
|
5642 |
|
5643 |
|
5644 |
|
5645 |
|
5646 |
|
5647 |
|
5648 |
|
5649 |
|
5650 |
|
5651 |
|
5652 |
|
5653 |
|
5654 |
|
5655 |
|
5656 | var AnimatePresence = function (_a) {
|
5657 | var children = _a.children, custom = _a.custom, _b = _a.initial, initial = _b === void 0 ? true : _b, onExitComplete = _a.onExitComplete, exitBeforeEnter = _a.exitBeforeEnter;
|
5658 |
|
5659 |
|
5660 | var forceRender = useForceUpdate();
|
5661 | var layoutContext = useContext(SharedLayoutContext);
|
5662 | if (isSharedLayout(layoutContext)) {
|
5663 | forceRender = layoutContext.forceUpdate;
|
5664 | }
|
5665 | var isInitialRender = useRef(true);
|
5666 |
|
5667 | var filteredChildren = onlyElements(children);
|
5668 |
|
5669 |
|
5670 | var presentChildren = useRef(filteredChildren);
|
5671 |
|
5672 | var allChildren = useRef(new Map())
|
5673 | .current;
|
5674 |
|
5675 | var exiting = useRef(new Set()).current;
|
5676 | updateChildLookup(filteredChildren, allChildren);
|
5677 |
|
5678 |
|
5679 | if (isInitialRender.current) {
|
5680 | isInitialRender.current = false;
|
5681 | return (createElement(Fragment, null, filteredChildren.map(function (child) { return (createElement(PresenceChild, { key: getChildKey(child), isPresent: true, initial: initial ? undefined : false }, child)); })));
|
5682 | }
|
5683 |
|
5684 | var childrenToRender = __spreadArrays(filteredChildren);
|
5685 |
|
5686 |
|
5687 | var presentKeys = presentChildren.current.map(getChildKey);
|
5688 | var targetKeys = filteredChildren.map(getChildKey);
|
5689 |
|
5690 | var numPresent = presentKeys.length;
|
5691 | for (var i = 0; i < numPresent; i++) {
|
5692 | var key = presentKeys[i];
|
5693 | if (targetKeys.indexOf(key) === -1) {
|
5694 | exiting.add(key);
|
5695 | }
|
5696 | else {
|
5697 |
|
5698 | exiting.delete(key);
|
5699 | }
|
5700 | }
|
5701 |
|
5702 |
|
5703 | if (exitBeforeEnter && exiting.size) {
|
5704 | childrenToRender = [];
|
5705 | }
|
5706 |
|
5707 |
|
5708 | exiting.forEach(function (key) {
|
5709 |
|
5710 | if (targetKeys.indexOf(key) !== -1)
|
5711 | return;
|
5712 | var child = allChildren.get(key);
|
5713 | if (!child)
|
5714 | return;
|
5715 | var insertionIndex = presentKeys.indexOf(key);
|
5716 | var onExit = function () {
|
5717 | allChildren.delete(key);
|
5718 | exiting.delete(key);
|
5719 |
|
5720 | var removeIndex = presentChildren.current.findIndex(function (presentChild) { return presentChild.key === key; });
|
5721 | presentChildren.current.splice(removeIndex, 1);
|
5722 |
|
5723 | if (!exiting.size) {
|
5724 | presentChildren.current = filteredChildren;
|
5725 | forceRender();
|
5726 | onExitComplete && onExitComplete();
|
5727 | }
|
5728 | };
|
5729 | childrenToRender.splice(insertionIndex, 0, createElement(PresenceChild, { key: getChildKey(child), isPresent: false, onExitComplete: onExit, custom: custom }, child));
|
5730 | });
|
5731 |
|
5732 |
|
5733 | childrenToRender = childrenToRender.map(function (child) {
|
5734 | var key = child.key;
|
5735 | return exiting.has(key) ? (child) : (createElement(PresenceChild, { key: getChildKey(child), isPresent: true }, child));
|
5736 | });
|
5737 | presentChildren.current = childrenToRender;
|
5738 | if (process.env.NODE_ENV !== "production" &&
|
5739 | exitBeforeEnter &&
|
5740 | childrenToRender.length > 1) {
|
5741 | console.warn("You're attempting to animate multiple children within AnimatePresence, but its exitBeforeEnter prop is set to true. This will lead to odd visual behaviour.");
|
5742 | }
|
5743 | return (createElement(Fragment, null, exiting.size
|
5744 | ? childrenToRender
|
5745 | : childrenToRender.map(function (child) { return cloneElement(child); })));
|
5746 | };
|
5747 |
|
5748 | function createSwitchAnimation(child, stack) {
|
5749 | if (stack && child !== stack.lead) {
|
5750 | return { visibilityAction: VisibilityAction.Hide };
|
5751 | }
|
5752 | else if (stack &&
|
5753 | child.presence !== Presence.Entering &&
|
5754 | child === stack.lead &&
|
5755 | stack.lead !== stack.prevLead) {
|
5756 | return { visibilityAction: VisibilityAction.Show };
|
5757 | }
|
5758 | var originBox;
|
5759 | var targetBox;
|
5760 | if (child.presence === Presence.Entering) {
|
5761 | originBox = stack === null || stack === void 0 ? void 0 : stack.getFollowOrigin();
|
5762 | }
|
5763 | else if (child.presence === Presence.Exiting) {
|
5764 | targetBox = stack === null || stack === void 0 ? void 0 : stack.getFollowTarget();
|
5765 | }
|
5766 | return { originBox: originBox, targetBox: targetBox };
|
5767 | }
|
5768 | function createCrossfadeAnimation(child, stack) {
|
5769 | var _a, _b, _c;
|
5770 | var config = {};
|
5771 | var stackLead = stack && stack.lead;
|
5772 | var stackLeadPresence = stackLead === null || stackLead === void 0 ? void 0 : stackLead.presence;
|
5773 | if (stack && child === stackLead) {
|
5774 | if (child.presence === Presence.Entering) {
|
5775 | config.originBox = stack.getFollowOrigin();
|
5776 | }
|
5777 | else if (child.presence === Presence.Exiting) {
|
5778 | config.targetBox = stack.getFollowTarget();
|
5779 | }
|
5780 | }
|
5781 | else if (stack && child === stack.follow) {
|
5782 | config.transition = stack.getLeadTransition();
|
5783 | if (stackLeadPresence === Presence.Entering) {
|
5784 | config.targetBox = stack.getLeadTarget();
|
5785 | }
|
5786 | else if (stackLeadPresence === Presence.Exiting) {
|
5787 | config.originBox = stack.getLeadOrigin();
|
5788 | }
|
5789 | }
|
5790 |
|
5791 |
|
5792 | if (!((_a = stack === null || stack === void 0 ? void 0 : stack.follow) === null || _a === void 0 ? void 0 : _a.isPresenceRoot) && !(stackLead === null || stackLead === void 0 ? void 0 : stackLead.isPresenceRoot)) {
|
5793 | return config;
|
5794 | }
|
5795 | if (!stack || child === stackLead) {
|
5796 | if (child.presence === Presence.Entering) {
|
5797 | config.crossfadeOpacity = (_b = stack === null || stack === void 0 ? void 0 : stack.follow) === null || _b === void 0 ? void 0 : _b.getValue("opacity", 0);
|
5798 | }
|
5799 | }
|
5800 | else if (stack && child === stack.follow) {
|
5801 | if (!stackLead || stackLeadPresence === Presence.Entering) ;
|
5802 | else if (stackLeadPresence === Presence.Exiting) {
|
5803 | config.crossfadeOpacity = (_c = stack === null || stack === void 0 ? void 0 : stack.lead) === null || _c === void 0 ? void 0 : _c.getValue("opacity", 1);
|
5804 | }
|
5805 | }
|
5806 | else {
|
5807 | config.visibilityAction = VisibilityAction.Hide;
|
5808 | }
|
5809 | return config;
|
5810 | }
|
5811 |
|
5812 |
|
5813 |
|
5814 |
|
5815 |
|
5816 |
|
5817 |
|
5818 |
|
5819 |
|
5820 |
|
5821 |
|
5822 |
|
5823 |
|
5824 |
|
5825 |
|
5826 |
|
5827 |
|
5828 |
|
5829 | function findLeadAndFollow(stack, _a) {
|
5830 | var prevLead = _a[0], prevFollow = _a[1];
|
5831 | var lead = undefined;
|
5832 | var leadIndex = 0;
|
5833 | var follow = undefined;
|
5834 |
|
5835 | var numInStack = stack.length;
|
5836 | var lastIsPresent = false;
|
5837 | for (var i = numInStack - 1; i >= 0; i--) {
|
5838 | var child = stack[i];
|
5839 | var isLastInStack = i === numInStack - 1;
|
5840 | if (isLastInStack)
|
5841 | lastIsPresent = child.isPresent;
|
5842 | if (lastIsPresent) {
|
5843 | lead = child;
|
5844 | }
|
5845 | else {
|
5846 |
|
5847 |
|
5848 | var prev = stack[i - 1];
|
5849 | if (prev && prev.isPresent)
|
5850 | lead = child;
|
5851 | }
|
5852 | if (lead) {
|
5853 | leadIndex = i;
|
5854 | break;
|
5855 | }
|
5856 | }
|
5857 | if (!lead)
|
5858 | lead = stack[0];
|
5859 |
|
5860 | follow = stack[leadIndex - 1];
|
5861 |
|
5862 |
|
5863 | if (lead) {
|
5864 | for (var i = leadIndex - 1; i >= 0; i--) {
|
5865 | var child = stack[i];
|
5866 | if (child.isPresent) {
|
5867 | follow = child;
|
5868 | break;
|
5869 | }
|
5870 | }
|
5871 | }
|
5872 |
|
5873 |
|
5874 |
|
5875 |
|
5876 |
|
5877 | if (lead !== prevLead &&
|
5878 | !lastIsPresent &&
|
5879 | follow === prevFollow &&
|
5880 | stack.find(function (stackChild) { return stackChild === prevLead; })) {
|
5881 | lead = prevLead;
|
5882 | }
|
5883 | return [lead, follow];
|
5884 | }
|
5885 | var LayoutStack = (function () {
|
5886 | function LayoutStack() {
|
5887 | this.order = [];
|
5888 |
|
5889 | this.hasChildren = false;
|
5890 | }
|
5891 | LayoutStack.prototype.add = function (child) {
|
5892 | var _a;
|
5893 | var layoutOrder = child.config.layoutOrder;
|
5894 | if (layoutOrder === undefined) {
|
5895 | this.order.push(child);
|
5896 | }
|
5897 | else {
|
5898 | var index = this.order.findIndex(function (stackChild) {
|
5899 | return layoutOrder <= (stackChild.config.layoutOrder || 0);
|
5900 | });
|
5901 | if (index === -1) {
|
5902 | child.presence = this.hasChildren
|
5903 | ? Presence.Entering
|
5904 | : Presence.Present;
|
5905 | index = this.order.length;
|
5906 | }
|
5907 | this.order.splice(index, 0, child);
|
5908 | }
|
5909 | |
5910 |
|
5911 |
|
5912 |
|
5913 |
|
5914 |
|
5915 |
|
5916 | if (this.snapshot) {
|
5917 | child.prevSnapshot = this.snapshot;
|
5918 |
|
5919 | child.prevViewportBox = this.snapshot.boundingBox;
|
5920 | var latest = this.snapshot.latestMotionValues;
|
5921 | for (var key in latest) {
|
5922 | if (!child.hasValue(key)) {
|
5923 | child.addValue(key, motionValue(latest[key]));
|
5924 | }
|
5925 | else {
|
5926 | (_a = child.getValue(key)) === null || _a === void 0 ? void 0 : _a.set(latest[key]);
|
5927 | }
|
5928 | }
|
5929 | }
|
5930 | this.hasChildren = true;
|
5931 | };
|
5932 | LayoutStack.prototype.remove = function (child) {
|
5933 | var index = this.order.findIndex(function (stackChild) { return child === stackChild; });
|
5934 | if (index !== -1)
|
5935 | this.order.splice(index, 1);
|
5936 | };
|
5937 | LayoutStack.prototype.updateLeadAndFollow = function () {
|
5938 | this.prevLead = this.lead;
|
5939 | this.prevFollow = this.follow;
|
5940 | var _a = findLeadAndFollow(this.order, [
|
5941 | this.lead,
|
5942 | this.follow,
|
5943 | ]), lead = _a[0], follow = _a[1];
|
5944 | this.lead = lead;
|
5945 | this.follow = follow;
|
5946 | };
|
5947 | LayoutStack.prototype.updateSnapshot = function () {
|
5948 | if (!this.lead)
|
5949 | return;
|
5950 | var snapshot = {
|
5951 | boundingBox: this.lead.prevViewportBox,
|
5952 | latestMotionValues: {},
|
5953 | };
|
5954 | this.lead.forEachValue(function (value, key) {
|
5955 | var latest = value.get();
|
5956 | if (!isTransformProp(latest)) {
|
5957 | snapshot.latestMotionValues[key] = latest;
|
5958 | }
|
5959 | });
|
5960 | var dragControls = elementDragControls.get(this.lead);
|
5961 | if (dragControls && dragControls.isDragging) {
|
5962 | snapshot.isDragging = true;
|
5963 | snapshot.cursorProgress = dragControls.cursorProgress;
|
5964 | }
|
5965 | this.snapshot = snapshot;
|
5966 | };
|
5967 | LayoutStack.prototype.isLeadPresent = function () {
|
5968 | var _a;
|
5969 | return this.lead && ((_a = this.lead) === null || _a === void 0 ? void 0 : _a.presence) !== Presence.Exiting;
|
5970 | };
|
5971 | LayoutStack.prototype.shouldStackAnimate = function () {
|
5972 | return true;
|
5973 |
|
5974 |
|
5975 |
|
5976 | };
|
5977 | LayoutStack.prototype.getFollowOrigin = function () {
|
5978 | var _a;
|
5979 |
|
5980 |
|
5981 | return this.follow
|
5982 | ? this.follow.prevViewportBox
|
5983 | : (_a = this.snapshot) === null || _a === void 0 ? void 0 : _a.boundingBox;
|
5984 | };
|
5985 | LayoutStack.prototype.getFollowTarget = function () {
|
5986 | var _a;
|
5987 | return (_a = this.follow) === null || _a === void 0 ? void 0 : _a.box;
|
5988 | };
|
5989 | LayoutStack.prototype.getLeadOrigin = function () {
|
5990 | var _a;
|
5991 | return (_a = this.lead) === null || _a === void 0 ? void 0 : _a.prevViewportBox;
|
5992 | };
|
5993 | LayoutStack.prototype.getLeadTarget = function () {
|
5994 | var _a;
|
5995 | return (_a = this.lead) === null || _a === void 0 ? void 0 : _a.box;
|
5996 | };
|
5997 | LayoutStack.prototype.getLeadTransition = function () {
|
5998 | var _a;
|
5999 | return (_a = this.lead) === null || _a === void 0 ? void 0 : _a.config.transition;
|
6000 | };
|
6001 | return LayoutStack;
|
6002 | }());
|
6003 |
|
6004 |
|
6005 |
|
6006 |
|
6007 | var AnimateSharedLayout = (function (_super) {
|
6008 | __extends(AnimateSharedLayout, _super);
|
6009 | function AnimateSharedLayout() {
|
6010 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
6011 | |
6012 |
|
6013 |
|
6014 | _this.children = new Set();
|
6015 | |
6016 |
|
6017 |
|
6018 |
|
6019 |
|
6020 | _this.stacks = new Map();
|
6021 | |
6022 |
|
6023 |
|
6024 |
|
6025 | _this.hasMounted = false;
|
6026 | |
6027 |
|
6028 |
|
6029 |
|
6030 | _this.updateScheduled = false;
|
6031 | |
6032 |
|
6033 |
|
6034 | _this.renderScheduled = false;
|
6035 | |
6036 |
|
6037 |
|
6038 | _this.syncContext = __assign(__assign({}, createBatcher()), { syncUpdate: function (force) { return _this.scheduleUpdate(force); }, forceUpdate: function () {
|
6039 |
|
6040 |
|
6041 | _this.syncContext = __assign({}, _this.syncContext);
|
6042 | _this.scheduleUpdate(true);
|
6043 | }, register: function (child) { return _this.addChild(child); }, remove: function (child) { return _this.removeChild(child); } });
|
6044 | return _this;
|
6045 | }
|
6046 | AnimateSharedLayout.prototype.componentDidMount = function () {
|
6047 | this.hasMounted = true;
|
6048 | this.updateStacks();
|
6049 | };
|
6050 | AnimateSharedLayout.prototype.componentDidUpdate = function () {
|
6051 | this.startLayoutAnimation();
|
6052 | };
|
6053 | AnimateSharedLayout.prototype.shouldComponentUpdate = function () {
|
6054 | this.renderScheduled = true;
|
6055 | return true;
|
6056 | };
|
6057 | AnimateSharedLayout.prototype.startLayoutAnimation = function () {
|
6058 | var _this = this;
|
6059 | |
6060 |
|
6061 |
|
6062 | this.renderScheduled = this.updateScheduled = false;
|
6063 | var type = this.props.type;
|
6064 | |
6065 |
|
6066 |
|
6067 |
|
6068 | this.children.forEach(function (child) {
|
6069 | if (!child.isPresent) {
|
6070 | child.presence = Presence.Exiting;
|
6071 | }
|
6072 | else if (child.presence !== Presence.Entering) {
|
6073 | child.presence =
|
6074 | child.presence === Presence.Exiting
|
6075 | ? Presence.Entering
|
6076 | : Presence.Present;
|
6077 | }
|
6078 | });
|
6079 | |
6080 |
|
6081 |
|
6082 |
|
6083 | this.updateStacks();
|
6084 | |
6085 |
|
6086 |
|
6087 | var createAnimation = type === "crossfade"
|
6088 | ? createCrossfadeAnimation
|
6089 | : createSwitchAnimation;
|
6090 | |
6091 |
|
6092 |
|
6093 | var handler = {
|
6094 | measureLayout: function (child) { return child.measureLayout(); },
|
6095 | layoutReady: function (child) {
|
6096 | var layoutId = child.layoutId;
|
6097 | child.layoutReady(createAnimation(child, _this.getStack(layoutId)));
|
6098 | },
|
6099 | };
|
6100 | |
6101 |
|
6102 |
|
6103 |
|
6104 |
|
6105 |
|
6106 |
|
6107 | this.children.forEach(function (child) { return _this.syncContext.add(child); });
|
6108 | this.syncContext.flush(handler);
|
6109 | |
6110 |
|
6111 |
|
6112 | this.stacks.forEach(function (stack) { return (stack.snapshot = undefined); });
|
6113 | };
|
6114 | AnimateSharedLayout.prototype.updateStacks = function () {
|
6115 | this.stacks.forEach(function (stack) { return stack.updateLeadAndFollow(); });
|
6116 | };
|
6117 | AnimateSharedLayout.prototype.scheduleUpdate = function (force) {
|
6118 | if (force === void 0) { force = false; }
|
6119 | if (!(force || !this.updateScheduled))
|
6120 | return;
|
6121 | |
6122 |
|
6123 |
|
6124 | this.updateScheduled = true;
|
6125 | |
6126 |
|
6127 |
|
6128 | this.children.forEach(function (child) { return child.snapshotBoundingBox(); });
|
6129 | |
6130 |
|
6131 |
|
6132 |
|
6133 |
|
6134 | this.stacks.forEach(function (stack) { return stack.updateSnapshot(); });
|
6135 | |
6136 |
|
6137 |
|
6138 | if (force || !this.renderScheduled) {
|
6139 | this.renderScheduled = true;
|
6140 | this.forceUpdate();
|
6141 | }
|
6142 | };
|
6143 | AnimateSharedLayout.prototype.addChild = function (child) {
|
6144 | this.children.add(child);
|
6145 | this.addToStack(child);
|
6146 | child.presence = this.hasMounted ? Presence.Entering : Presence.Present;
|
6147 | };
|
6148 | AnimateSharedLayout.prototype.removeChild = function (child) {
|
6149 | this.scheduleUpdate();
|
6150 | this.children.delete(child);
|
6151 | this.removeFromStack(child);
|
6152 | };
|
6153 | AnimateSharedLayout.prototype.addToStack = function (child) {
|
6154 | var stack = this.getStack(child.layoutId);
|
6155 | stack === null || stack === void 0 ? void 0 : stack.add(child);
|
6156 | };
|
6157 | AnimateSharedLayout.prototype.removeFromStack = function (child) {
|
6158 | var stack = this.getStack(child.layoutId);
|
6159 | stack === null || stack === void 0 ? void 0 : stack.remove(child);
|
6160 | };
|
6161 | |
6162 |
|
6163 |
|
6164 |
|
6165 | AnimateSharedLayout.prototype.getStack = function (id) {
|
6166 | if (id === undefined)
|
6167 | return;
|
6168 |
|
6169 | !this.stacks.has(id) && this.stacks.set(id, new LayoutStack());
|
6170 | return this.stacks.get(id);
|
6171 | };
|
6172 | AnimateSharedLayout.prototype.render = function () {
|
6173 | return (createElement(SharedLayoutContext.Provider, { value: this.syncContext }, this.props.children));
|
6174 | };
|
6175 | return AnimateSharedLayout;
|
6176 | }(Component$1));
|
6177 |
|
6178 |
|
6179 |
|
6180 |
|
6181 |
|
6182 |
|
6183 |
|
6184 |
|
6185 |
|
6186 |
|
6187 |
|
6188 |
|
6189 |
|
6190 |
|
6191 |
|
6192 |
|
6193 |
|
6194 |
|
6195 |
|
6196 |
|
6197 |
|
6198 |
|
6199 |
|
6200 |
|
6201 |
|
6202 |
|
6203 |
|
6204 |
|
6205 |
|
6206 |
|
6207 | function useMotionValue(initial) {
|
6208 | return useConstant(function () { return motionValue(initial); });
|
6209 | }
|
6210 |
|
6211 |
|
6212 |
|
6213 |
|
6214 |
|
6215 |
|
6216 |
|
6217 |
|
6218 | function resolveMotionValue(value) {
|
6219 | var unwrappedValue = value instanceof MotionValue ? value.get() : value;
|
6220 | return isCustomValue(unwrappedValue)
|
6221 | ? unwrappedValue.toValue()
|
6222 | : unwrappedValue;
|
6223 | }
|
6224 |
|
6225 | var isCustomValueType = function (v) {
|
6226 | return typeof v === "object" && v.mix;
|
6227 | };
|
6228 | var getMixer = function (v) { return (isCustomValueType(v) ? v.mix : undefined); };
|
6229 | function transform() {
|
6230 | var args = [];
|
6231 | for (var _i = 0; _i < arguments.length; _i++) {
|
6232 | args[_i] = arguments[_i];
|
6233 | }
|
6234 | var useImmediate = !Array.isArray(args[0]);
|
6235 | var argOffset = useImmediate ? 0 : -1;
|
6236 | var inputValue = args[0 + argOffset];
|
6237 | var inputRange = args[1 + argOffset];
|
6238 | var outputRange = args[2 + argOffset];
|
6239 | var options = args[3 + argOffset];
|
6240 | var interpolator = interpolate(inputRange, outputRange, __assign({ mixer: getMixer(outputRange[0]) }, options));
|
6241 | return useImmediate ? interpolator(inputValue) : interpolator;
|
6242 | }
|
6243 |
|
6244 | var isTransformer = function (v) {
|
6245 | return typeof v === "function";
|
6246 | };
|
6247 | function useTransform(parent, customTransform, to, options) {
|
6248 | var comparitor = isTransformer(customTransform)
|
6249 | ? [parent]
|
6250 | : [parent, customTransform.join(","), to === null || to === void 0 ? void 0 : to.join(",")];
|
6251 | var transformer = useMemo(function () {
|
6252 | return isTransformer(customTransform)
|
6253 | ? customTransform
|
6254 | : transform(customTransform, to, options);
|
6255 | }, comparitor);
|
6256 | var initialValue = transformer(parent.get());
|
6257 | var value = useMotionValue(initialValue);
|
6258 |
|
6259 | var unsubscribe = useRef();
|
6260 | useMemo(function () {
|
6261 | unsubscribe.current && unsubscribe.current();
|
6262 | unsubscribe.current = parent.onChange(function (v) { return value.set(transformer(v)); });
|
6263 |
|
6264 | value.set(initialValue);
|
6265 | }, [parent, value, transformer]);
|
6266 | useUnmountEffect(function () { return unsubscribe.current && unsubscribe.current(); });
|
6267 | return value;
|
6268 | }
|
6269 |
|
6270 |
|
6271 |
|
6272 |
|
6273 | var maxScale = 100000;
|
6274 | var invertScale = function (scale) {
|
6275 | return scale > 0.001 ? 1 / scale : maxScale;
|
6276 | };
|
6277 |
|
6278 |
|
6279 |
|
6280 |
|
6281 |
|
6282 |
|
6283 |
|
6284 |
|
6285 |
|
6286 |
|
6287 |
|
6288 |
|
6289 |
|
6290 |
|
6291 |
|
6292 |
|
6293 |
|
6294 |
|
6295 |
|
6296 |
|
6297 |
|
6298 |
|
6299 |
|
6300 |
|
6301 |
|
6302 |
|
6303 |
|
6304 |
|
6305 |
|
6306 |
|
6307 | function useInvertedScale(scale) {
|
6308 | var parentScaleX = useMotionValue(1);
|
6309 | var parentScaleY = useMotionValue(1);
|
6310 | var visualElement = useContext(MotionContext).visualElement;
|
6311 | invariant(!!(scale || visualElement), "If no scale values are provided, useInvertedScale must be used within a child of another motion component.");
|
6312 | if (scale) {
|
6313 | parentScaleX = scale.scaleX || parentScaleX;
|
6314 | parentScaleY = scale.scaleY || parentScaleY;
|
6315 | }
|
6316 | else if (visualElement) {
|
6317 | parentScaleX = visualElement.getValue("scaleX", 1);
|
6318 | parentScaleY = visualElement.getValue("scaleY", 1);
|
6319 | }
|
6320 | var scaleX = useTransform(parentScaleX, invertScale);
|
6321 | var scaleY = useTransform(parentScaleY, invertScale);
|
6322 | return { scaleX: scaleX, scaleY: scaleY };
|
6323 | }
|
6324 |
|
6325 | function useOnChange(value, callback) {
|
6326 | useEffect(function () { return (isMotionValue(value) ? value.onChange(callback) : undefined); }, [value]);
|
6327 | }
|
6328 |
|
6329 |
|
6330 |
|
6331 |
|
6332 |
|
6333 |
|
6334 |
|
6335 |
|
6336 |
|
6337 |
|
6338 |
|
6339 |
|
6340 |
|
6341 |
|
6342 |
|
6343 |
|
6344 |
|
6345 |
|
6346 |
|
6347 |
|
6348 | function useSpring(source, config) {
|
6349 | if (config === void 0) { config = {}; }
|
6350 | var activeSpringAnimation = useRef(null);
|
6351 | var value = useMotionValue(isMotionValue(source) ? source.get() : source);
|
6352 | useMemo(function () {
|
6353 | return value.attach(function (v, set) {
|
6354 | if (activeSpringAnimation.current) {
|
6355 | activeSpringAnimation.current.stop();
|
6356 | }
|
6357 | activeSpringAnimation.current = spring(__assign({ from: value.get(), to: v, velocity: value.getVelocity() }, config)).start(set);
|
6358 | return value.get();
|
6359 | });
|
6360 | }, Object.values(config));
|
6361 | useOnChange(source, function (v) { return value.set(parseFloat(v)); });
|
6362 | return value;
|
6363 | }
|
6364 |
|
6365 | function createScrollMotionValues() {
|
6366 | return {
|
6367 | scrollX: motionValue(0),
|
6368 | scrollY: motionValue(0),
|
6369 | scrollXProgress: motionValue(0),
|
6370 | scrollYProgress: motionValue(0),
|
6371 | };
|
6372 | }
|
6373 | function setProgress(offset, maxOffset, value) {
|
6374 | value.set(!offset || !maxOffset ? 0 : offset / maxOffset);
|
6375 | }
|
6376 | function createScrollUpdater(values, getOffsets) {
|
6377 | var update = function () {
|
6378 | var _a = getOffsets(), xOffset = _a.xOffset, yOffset = _a.yOffset, xMaxOffset = _a.xMaxOffset, yMaxOffset = _a.yMaxOffset;
|
6379 |
|
6380 | values.scrollX.set(xOffset);
|
6381 | values.scrollY.set(yOffset);
|
6382 |
|
6383 | setProgress(xOffset, xMaxOffset, values.scrollXProgress);
|
6384 | setProgress(yOffset, yMaxOffset, values.scrollYProgress);
|
6385 | };
|
6386 | update();
|
6387 | return update;
|
6388 | }
|
6389 |
|
6390 | var isBrowser$2 = typeof window !== "undefined";
|
6391 | var useIsomorphicLayoutEffect = isBrowser$2 ? useLayoutEffect : useEffect;
|
6392 |
|
6393 | var getElementScrollOffsets = function (element) { return function () {
|
6394 | return {
|
6395 | xOffset: element.scrollLeft,
|
6396 | yOffset: element.scrollTop,
|
6397 | xMaxOffset: element.scrollWidth - element.offsetWidth,
|
6398 | yMaxOffset: element.scrollHeight - element.offsetHeight,
|
6399 | };
|
6400 | }; };
|
6401 |
|
6402 |
|
6403 |
|
6404 |
|
6405 |
|
6406 |
|
6407 |
|
6408 |
|
6409 |
|
6410 |
|
6411 |
|
6412 |
|
6413 |
|
6414 |
|
6415 |
|
6416 |
|
6417 |
|
6418 |
|
6419 |
|
6420 |
|
6421 |
|
6422 |
|
6423 |
|
6424 |
|
6425 |
|
6426 |
|
6427 |
|
6428 |
|
6429 |
|
6430 |
|
6431 |
|
6432 |
|
6433 |
|
6434 |
|
6435 |
|
6436 |
|
6437 |
|
6438 |
|
6439 |
|
6440 |
|
6441 |
|
6442 |
|
6443 |
|
6444 |
|
6445 |
|
6446 |
|
6447 |
|
6448 |
|
6449 |
|
6450 | function useElementScroll(ref) {
|
6451 | var values = useConstant(createScrollMotionValues);
|
6452 | useIsomorphicLayoutEffect(function () {
|
6453 | var element = ref.current;
|
6454 | invariant(!!element, "ref provided to useScroll must be passed into a HTML element.");
|
6455 | if (!element)
|
6456 | return;
|
6457 | var updateScrollValues = createScrollUpdater(values, getElementScrollOffsets(element));
|
6458 | var scrollListener = addDomEvent(element, "scroll", updateScrollValues, { passive: true });
|
6459 | var resizeListener = addDomEvent(element, "resize", updateScrollValues);
|
6460 | return function () {
|
6461 | scrollListener && scrollListener();
|
6462 | resizeListener && resizeListener();
|
6463 | };
|
6464 | }, []);
|
6465 | return values;
|
6466 | }
|
6467 |
|
6468 | var viewportScrollValues = createScrollMotionValues();
|
6469 | function getViewportScrollOffsets() {
|
6470 | return {
|
6471 | xOffset: window.pageXOffset,
|
6472 | yOffset: window.pageYOffset,
|
6473 | xMaxOffset: document.body.clientWidth - window.innerWidth,
|
6474 | yMaxOffset: document.body.clientHeight - window.innerHeight,
|
6475 | };
|
6476 | }
|
6477 | var hasListeners = false;
|
6478 | function addEventListeners() {
|
6479 | hasListeners = true;
|
6480 | if (typeof window === "undefined")
|
6481 | return;
|
6482 | var updateScrollValues = createScrollUpdater(viewportScrollValues, getViewportScrollOffsets);
|
6483 | addDomEvent(window, "scroll", updateScrollValues, { passive: true });
|
6484 | addDomEvent(window, "resize", updateScrollValues);
|
6485 | }
|
6486 |
|
6487 |
|
6488 |
|
6489 |
|
6490 |
|
6491 |
|
6492 |
|
6493 |
|
6494 |
|
6495 |
|
6496 |
|
6497 |
|
6498 |
|
6499 |
|
6500 |
|
6501 |
|
6502 |
|
6503 |
|
6504 |
|
6505 |
|
6506 |
|
6507 |
|
6508 |
|
6509 |
|
6510 |
|
6511 |
|
6512 |
|
6513 |
|
6514 |
|
6515 |
|
6516 |
|
6517 |
|
6518 |
|
6519 |
|
6520 |
|
6521 | function useViewportScroll() {
|
6522 | useIsomorphicLayoutEffect(function () {
|
6523 | !hasListeners && addEventListeners();
|
6524 | }, []);
|
6525 | return viewportScrollValues;
|
6526 | }
|
6527 |
|
6528 |
|
6529 |
|
6530 |
|
6531 |
|
6532 |
|
6533 |
|
6534 |
|
6535 |
|
6536 |
|
6537 |
|
6538 |
|
6539 |
|
6540 |
|
6541 |
|
6542 |
|
6543 |
|
6544 |
|
6545 |
|
6546 |
|
6547 |
|
6548 |
|
6549 |
|
6550 |
|
6551 |
|
6552 |
|
6553 |
|
6554 |
|
6555 |
|
6556 |
|
6557 |
|
6558 |
|
6559 |
|
6560 |
|
6561 |
|
6562 |
|
6563 |
|
6564 |
|
6565 |
|
6566 |
|
6567 |
|
6568 |
|
6569 |
|
6570 |
|
6571 |
|
6572 |
|
6573 |
|
6574 |
|
6575 |
|
6576 |
|
6577 | function useAnimation() {
|
6578 | var animationControls = useConstant(function () { return new AnimationControls(); });
|
6579 | useEffect(function () {
|
6580 | animationControls.mount();
|
6581 | return function () { return animationControls.unmount(); };
|
6582 | }, []);
|
6583 | return animationControls;
|
6584 | }
|
6585 |
|
6586 |
|
6587 |
|
6588 |
|
6589 |
|
6590 |
|
6591 |
|
6592 |
|
6593 |
|
6594 |
|
6595 |
|
6596 |
|
6597 |
|
6598 |
|
6599 |
|
6600 |
|
6601 |
|
6602 |
|
6603 |
|
6604 |
|
6605 |
|
6606 |
|
6607 |
|
6608 |
|
6609 |
|
6610 |
|
6611 |
|
6612 |
|
6613 |
|
6614 |
|
6615 |
|
6616 |
|
6617 |
|
6618 |
|
6619 |
|
6620 |
|
6621 |
|
6622 |
|
6623 |
|
6624 |
|
6625 |
|
6626 |
|
6627 |
|
6628 |
|
6629 |
|
6630 |
|
6631 |
|
6632 | function useCycle() {
|
6633 | var items = [];
|
6634 | for (var _i = 0; _i < arguments.length; _i++) {
|
6635 | items[_i] = arguments[_i];
|
6636 | }
|
6637 |
|
6638 | warning(items.length > 1, "useCycle syntax has changed. `useCycle([0, 1, 2])` becomes `useCycle(0, 1, 2)`");
|
6639 | var index = useRef(0);
|
6640 | var _a = useState(items[index.current]), item = _a[0], setItem = _a[1];
|
6641 | return [
|
6642 | item,
|
6643 | function (next) {
|
6644 | index.current =
|
6645 | typeof next !== "number"
|
6646 | ? wrap(0, items.length, index.current + 1)
|
6647 | : next;
|
6648 | setItem(items[index.current]);
|
6649 | },
|
6650 | ];
|
6651 | }
|
6652 |
|
6653 |
|
6654 | var prefersReducedMotion = motionValue(null);
|
6655 | if (typeof window !== "undefined") {
|
6656 | if (window.matchMedia) {
|
6657 | var motionMediaQuery_1 = window.matchMedia("(prefers-reduced-motion)");
|
6658 | var setReducedMotionPreferences = function () {
|
6659 | return prefersReducedMotion.set(motionMediaQuery_1.matches);
|
6660 | };
|
6661 | motionMediaQuery_1.addListener(setReducedMotionPreferences);
|
6662 | setReducedMotionPreferences();
|
6663 | }
|
6664 | else {
|
6665 | prefersReducedMotion.set(false);
|
6666 | }
|
6667 | }
|
6668 | function determineShouldReduceMotion(prefersReduced, isReducedMotion) {
|
6669 | return typeof isReducedMotion === "boolean"
|
6670 | ? isReducedMotion
|
6671 | : Boolean(prefersReduced);
|
6672 | }
|
6673 |
|
6674 |
|
6675 |
|
6676 |
|
6677 |
|
6678 |
|
6679 |
|
6680 |
|
6681 |
|
6682 |
|
6683 |
|
6684 |
|
6685 |
|
6686 |
|
6687 |
|
6688 |
|
6689 |
|
6690 |
|
6691 |
|
6692 |
|
6693 |
|
6694 |
|
6695 |
|
6696 |
|
6697 |
|
6698 |
|
6699 | function useReducedMotion() {
|
6700 | var isReducedMotion = useContext(MotionContext).isReducedMotion;
|
6701 | var _a = useState(determineShouldReduceMotion(prefersReducedMotion.get(), isReducedMotion)), shouldReduceMotion = _a[0], setShouldReduceMotion = _a[1];
|
6702 | useEffect(function () {
|
6703 | return prefersReducedMotion.onChange(function (v) {
|
6704 | setShouldReduceMotion(determineShouldReduceMotion(v, isReducedMotion));
|
6705 | });
|
6706 | }, [setShouldReduceMotion, isReducedMotion]);
|
6707 | return shouldReduceMotion;
|
6708 | }
|
6709 |
|
6710 |
|
6711 |
|
6712 |
|
6713 |
|
6714 |
|
6715 |
|
6716 | function ReducedMotion(_a) {
|
6717 | var children = _a.children, enabled = _a.enabled;
|
6718 | var context = useContext(MotionContext);
|
6719 | context = useMemo(function () { return (__assign(__assign({}, context), { isReducedMotion: enabled })); }, [enabled]);
|
6720 | return (createElement(MotionContext.Provider, { value: context }, children));
|
6721 | }
|
6722 |
|
6723 |
|
6724 |
|
6725 |
|
6726 |
|
6727 |
|
6728 |
|
6729 |
|
6730 |
|
6731 |
|
6732 |
|
6733 |
|
6734 |
|
6735 |
|
6736 |
|
6737 |
|
6738 |
|
6739 |
|
6740 |
|
6741 |
|
6742 |
|
6743 |
|
6744 |
|
6745 |
|
6746 |
|
6747 |
|
6748 |
|
6749 |
|
6750 |
|
6751 |
|
6752 |
|
6753 |
|
6754 |
|
6755 |
|
6756 |
|
6757 |
|
6758 |
|
6759 |
|
6760 |
|
6761 |
|
6762 | var DragControls = (function () {
|
6763 | function DragControls() {
|
6764 | this.componentControls = new Set();
|
6765 | }
|
6766 | |
6767 |
|
6768 |
|
6769 |
|
6770 |
|
6771 | DragControls.prototype.subscribe = function (controls) {
|
6772 | var _this = this;
|
6773 | this.componentControls.add(controls);
|
6774 | return function () { return _this.componentControls.delete(controls); };
|
6775 | };
|
6776 | |
6777 |
|
6778 |
|
6779 |
|
6780 |
|
6781 |
|
6782 |
|
6783 |
|
6784 |
|
6785 |
|
6786 |
|
6787 |
|
6788 |
|
6789 |
|
6790 |
|
6791 | DragControls.prototype.start = function (event, options) {
|
6792 | this.componentControls.forEach(function (controls) {
|
6793 | controls.start(event.nativeEvent || event, options);
|
6794 | });
|
6795 | };
|
6796 | return DragControls;
|
6797 | }());
|
6798 | var createDragControls = function () { return new DragControls(); };
|
6799 |
|
6800 |
|
6801 |
|
6802 |
|
6803 |
|
6804 |
|
6805 |
|
6806 |
|
6807 |
|
6808 |
|
6809 |
|
6810 |
|
6811 |
|
6812 |
|
6813 |
|
6814 |
|
6815 |
|
6816 |
|
6817 |
|
6818 |
|
6819 |
|
6820 |
|
6821 |
|
6822 |
|
6823 |
|
6824 |
|
6825 |
|
6826 |
|
6827 |
|
6828 |
|
6829 |
|
6830 |
|
6831 |
|
6832 |
|
6833 |
|
6834 |
|
6835 |
|
6836 |
|
6837 |
|
6838 |
|
6839 |
|
6840 |
|
6841 |
|
6842 |
|
6843 |
|
6844 | function useDragControls() {
|
6845 | return useConstant(createDragControls);
|
6846 | }
|
6847 |
|
6848 |
|
6849 |
|
6850 |
|
6851 |
|
6852 |
|
6853 | function useExternalRef(externalRef) {
|
6854 |
|
6855 |
|
6856 |
|
6857 |
|
6858 | var ref = !externalRef || typeof externalRef === "function"
|
6859 | ? useRef(null)
|
6860 | : externalRef;
|
6861 |
|
6862 |
|
6863 |
|
6864 |
|
6865 |
|
6866 | if (externalRef && typeof externalRef === "function") {
|
6867 | useEffect(function () {
|
6868 | externalRef(ref.current);
|
6869 | return function () { return externalRef(null); };
|
6870 | }, []);
|
6871 | }
|
6872 | return ref;
|
6873 | }
|
6874 |
|
6875 |
|
6876 |
|
6877 |
|
6878 |
|
6879 | var StateVisualElement = (function (_super) {
|
6880 | __extends(StateVisualElement, _super);
|
6881 | function StateVisualElement() {
|
6882 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
6883 | _this.initialState = {};
|
6884 | return _this;
|
6885 | }
|
6886 | StateVisualElement.prototype.updateLayoutDelta = function () { };
|
6887 | StateVisualElement.prototype.build = function () { };
|
6888 | StateVisualElement.prototype.clean = function () { };
|
6889 | StateVisualElement.prototype.getBoundingBox = function () {
|
6890 | return { x: { min: 0, max: 0 }, y: { min: 0, max: 0 } };
|
6891 | };
|
6892 | StateVisualElement.prototype.readNativeValue = function (key) {
|
6893 | return this.initialState[key] || 0;
|
6894 | };
|
6895 | StateVisualElement.prototype.render = function () {
|
6896 | this.build();
|
6897 | };
|
6898 | return StateVisualElement;
|
6899 | }(VisualElement));
|
6900 |
|
6901 |
|
6902 |
|
6903 |
|
6904 |
|
6905 | function useAnimatedState(initialState) {
|
6906 | var _a = useState(initialState), animationState = _a[0], setAnimationState = _a[1];
|
6907 | var visualElement = useConstant(function () { return new StateVisualElement(); });
|
6908 | visualElement.updateConfig({
|
6909 | onUpdate: function (v) { return setAnimationState(__assign({}, v)); },
|
6910 | });
|
6911 | visualElement.initialState = initialState;
|
6912 | var controls = useVisualElementAnimation(visualElement, {}, {});
|
6913 | useEffect(function () {
|
6914 | visualElement.mount({});
|
6915 | return function () { return visualElement.unmount(); };
|
6916 | }, []);
|
6917 | var startAnimation = useConstant(function () { return function (animationDefinition) {
|
6918 | return controls.start(animationDefinition);
|
6919 | }; });
|
6920 | return [animationState, startAnimation];
|
6921 | }
|
6922 |
|
6923 | export { AnimateLayout as AnimateLayoutFeature, AnimatePresence, AnimateSharedLayout, AnimationControls, Animation as AnimationFeature, DragControls, Drag as DragFeature, Exit as ExitFeature, Gestures as GesturesFeature, MotionConfig, MotionConfigContext, MotionContext, MotionValue, PresenceContext, ReducedMotion, VisualElementAnimationControls, addScaleCorrection, animationControls, createMotionComponent, isValidMotionProp, m, motion, motionValue, resolveMotionValue, transform, useAnimatedState, useAnimation, useCycle, useDomEvent, useDragControls, useElementScroll, useExternalRef, useGestures, useInvertedScale, useIsPresent, useMotionValue, usePanGesture, usePresence, useReducedMotion, useSpring, useTapGesture, useTransform, useViewportScroll };
|