framer-motion 7.0.3 → 7.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +2090 -2304
- package/dist/es/animation/animate.mjs +4 -5
- package/dist/es/animation/animation-controls.mjs +22 -24
- package/dist/es/animation/use-animated-state.mjs +23 -25
- package/dist/es/animation/use-animation.mjs +2 -2
- package/dist/es/animation/utils/default-transitions.mjs +13 -14
- package/dist/es/animation/utils/easing.mjs +20 -21
- package/dist/es/animation/utils/is-animatable.mjs +1 -1
- package/dist/es/animation/utils/is-keyframes-target.mjs +1 -1
- package/dist/es/animation/utils/transitions.mjs +30 -31
- package/dist/es/components/AnimatePresence/PresenceChild.mjs +18 -31
- package/dist/es/components/AnimatePresence/index.mjs +33 -35
- package/dist/es/components/AnimatePresence/use-presence.mjs +5 -5
- package/dist/es/components/AnimateSharedLayout.mjs +4 -5
- package/dist/es/components/LayoutGroup/index.mjs +12 -16
- package/dist/es/components/LazyMotion/index.mjs +9 -10
- package/dist/es/components/MotionConfig/index.mjs +5 -5
- package/dist/es/components/Reorder/Group.mjs +16 -16
- package/dist/es/components/Reorder/Item.mjs +14 -18
- package/dist/es/components/Reorder/index.mjs +3 -3
- package/dist/es/components/Reorder/utils/check-reorder.mjs +6 -6
- package/dist/es/context/DeprecatedLayoutGroupContext.mjs +1 -1
- package/dist/es/context/LayoutGroupContext.mjs +1 -1
- package/dist/es/context/LazyContext.mjs +1 -1
- package/dist/es/context/MotionConfigContext.mjs +2 -2
- package/dist/es/context/MotionContext/create.mjs +2 -2
- package/dist/es/context/MotionContext/index.mjs +1 -1
- package/dist/es/context/MotionContext/utils.mjs +1 -1
- package/dist/es/context/PresenceContext.mjs +1 -1
- package/dist/es/context/ReorderContext.mjs +1 -1
- package/dist/es/context/SwitchLayoutGroupContext.mjs +1 -1
- package/dist/es/events/event-info.mjs +11 -17
- package/dist/es/events/use-dom-event.mjs +4 -5
- package/dist/es/events/use-pointer-event.mjs +2 -2
- package/dist/es/events/utils.mjs +3 -9
- package/dist/es/gestures/PanSession.mjs +42 -47
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +147 -157
- package/dist/es/gestures/drag/use-drag-controls.mjs +10 -12
- package/dist/es/gestures/drag/use-drag.mjs +4 -4
- package/dist/es/gestures/drag/utils/constraints.mjs +12 -17
- package/dist/es/gestures/drag/utils/lock.mjs +17 -17
- package/dist/es/gestures/use-focus-gesture.mjs +3 -4
- package/dist/es/gestures/use-hover-gesture.mjs +2 -3
- package/dist/es/gestures/use-pan-gesture.mjs +9 -10
- package/dist/es/gestures/use-tap-gesture.mjs +5 -6
- package/dist/es/gestures/utils/event-type.mjs +1 -1
- package/dist/es/gestures/utils/is-node-or-child.mjs +1 -1
- package/dist/es/index.mjs +1 -0
- package/dist/es/motion/features/animations.mjs +9 -11
- package/dist/es/motion/features/definitions.mjs +5 -5
- package/dist/es/motion/features/drag.mjs +1 -1
- package/dist/es/motion/features/gestures.mjs +1 -1
- package/dist/es/motion/features/layout/MeasureLayout.mjs +32 -40
- package/dist/es/motion/features/layout/index.mjs +1 -1
- package/dist/es/motion/features/use-features.mjs +8 -9
- package/dist/es/motion/features/use-projection.mjs +10 -11
- package/dist/es/motion/features/viewport/observers.mjs +12 -12
- package/dist/es/motion/features/viewport/use-viewport.mjs +17 -20
- package/dist/es/motion/index.mjs +13 -16
- package/dist/es/motion/utils/VisualElementHandler.mjs +10 -16
- package/dist/es/motion/utils/is-forced-motion-value.mjs +1 -2
- package/dist/es/motion/utils/make-renderless-component.mjs +2 -2
- package/dist/es/motion/utils/use-motion-ref.mjs +1 -1
- package/dist/es/motion/utils/use-visual-element.mjs +13 -13
- package/dist/es/motion/utils/use-visual-state.mjs +26 -31
- package/dist/es/motion/utils/valid-prop.mjs +1 -1
- package/dist/es/projection/animation/mix-values.mjs +12 -16
- package/dist/es/projection/geometry/conversion.mjs +4 -6
- package/dist/es/projection/geometry/delta-apply.mjs +14 -20
- package/dist/es/projection/geometry/delta-calc.mjs +2 -5
- package/dist/es/projection/geometry/delta-remove.mjs +6 -13
- package/dist/es/projection/geometry/models.mjs +7 -7
- package/dist/es/projection/node/DocumentProjectionNode.mjs +5 -5
- package/dist/es/projection/node/HTMLProjectionNode.mjs +8 -10
- package/dist/es/projection/node/create-projection-node.mjs +283 -307
- package/dist/es/projection/node/group.mjs +6 -8
- package/dist/es/projection/node/id.mjs +2 -2
- package/dist/es/projection/node/state.mjs +1 -1
- package/dist/es/projection/shared/stack.mjs +26 -27
- package/dist/es/projection/styles/scale-border-radius.mjs +5 -5
- package/dist/es/projection/styles/scale-box-shadow.mjs +18 -19
- package/dist/es/projection/styles/scale-correction.mjs +1 -1
- package/dist/es/projection/styles/transform.mjs +12 -12
- package/dist/es/projection/use-reset-projection.mjs +2 -2
- package/dist/es/projection/utils/has-transform.mjs +1 -2
- package/dist/es/projection/utils/measure.mjs +2 -2
- package/dist/es/render/dom/create-visual-element.mjs +1 -1
- package/dist/es/render/dom/features-animation.mjs +1 -2
- package/dist/es/render/dom/features-max.mjs +1 -2
- package/dist/es/render/dom/motion-minimal.mjs +1 -1
- package/dist/es/render/dom/motion-proxy.mjs +3 -4
- package/dist/es/render/dom/motion.mjs +2 -5
- package/dist/es/render/dom/use-render.mjs +6 -9
- package/dist/es/render/dom/utils/camel-to-dash.mjs +3 -5
- package/dist/es/render/dom/utils/create-config.mjs +5 -5
- package/dist/es/render/dom/utils/css-variables-conversion.mjs +19 -20
- package/dist/es/render/dom/utils/filter-props.mjs +4 -6
- package/dist/es/render/dom/utils/parse-dom-variant.mjs +2 -2
- package/dist/es/render/dom/utils/unit-conversion.mjs +68 -99
- package/dist/es/render/dom/value-types/animatable-none.mjs +1 -1
- package/dist/es/render/dom/value-types/defaults.mjs +4 -5
- package/dist/es/render/dom/value-types/dimensions.mjs +2 -4
- package/dist/es/render/dom/value-types/find.mjs +2 -3
- package/dist/es/render/dom/value-types/get-as-type.mjs +1 -1
- package/dist/es/render/dom/value-types/number.mjs +2 -2
- package/dist/es/render/dom/value-types/test.mjs +1 -1
- package/dist/es/render/dom/value-types/type-auto.mjs +3 -3
- package/dist/es/render/dom/value-types/type-int.mjs +1 -2
- package/dist/es/render/html/config-motion.mjs +1 -1
- package/dist/es/render/html/use-props.mjs +11 -13
- package/dist/es/render/html/utils/build-styles.mjs +8 -8
- package/dist/es/render/html/utils/build-transform.mjs +11 -16
- package/dist/es/render/html/utils/create-render-state.mjs +2 -2
- package/dist/es/render/html/utils/render.mjs +2 -3
- package/dist/es/render/html/utils/scrape-motion-values.mjs +3 -3
- package/dist/es/render/html/utils/transform.mjs +6 -10
- package/dist/es/render/html/visual-element.mjs +22 -23
- package/dist/es/render/index.mjs +359 -364
- package/dist/es/render/svg/config-motion.mjs +2 -3
- package/dist/es/render/svg/lowercase-elements.mjs +1 -1
- package/dist/es/render/svg/use-props.mjs +5 -6
- package/dist/es/render/svg/utils/build-attrs.mjs +2 -2
- package/dist/es/render/svg/utils/camel-case-attrs.mjs +1 -1
- package/dist/es/render/svg/utils/create-render-state.mjs +1 -2
- package/dist/es/render/svg/utils/path.mjs +7 -10
- package/dist/es/render/svg/utils/render.mjs +1 -1
- package/dist/es/render/svg/utils/scrape-motion-values.mjs +3 -3
- package/dist/es/render/svg/utils/transform-origin.mjs +3 -3
- package/dist/es/render/svg/visual-element.mjs +6 -4
- package/dist/es/render/utils/animation-state.mjs +71 -87
- package/dist/es/render/utils/animation.mjs +48 -60
- package/dist/es/render/utils/compare-by-depth.mjs +1 -3
- package/dist/es/render/utils/flat-tree.mjs +9 -10
- package/dist/es/render/utils/lifecycles.mjs +12 -19
- package/dist/es/render/utils/motion-values.mjs +16 -8
- package/dist/es/render/utils/setters.mjs +19 -19
- package/dist/es/render/utils/variants.mjs +6 -8
- package/dist/es/utils/array.mjs +9 -10
- package/dist/es/utils/is-browser.mjs +1 -1
- package/dist/es/utils/is-numerical-string.mjs +1 -1
- package/dist/es/utils/is-zero-value-string.mjs +1 -1
- package/dist/es/utils/process.mjs +2 -2
- package/dist/es/utils/resolve-value.mjs +2 -2
- package/dist/es/utils/shallow-compare.mjs +2 -2
- package/dist/es/utils/subscription-manager.mjs +15 -17
- package/dist/es/utils/time-conversion.mjs +1 -1
- package/dist/es/utils/transform.mjs +10 -15
- package/dist/es/utils/use-animation-frame.mjs +5 -6
- package/dist/es/utils/use-constant.mjs +1 -1
- package/dist/es/utils/use-cycle.mjs +9 -10
- package/dist/es/utils/use-force-update.mjs +4 -5
- package/dist/es/utils/use-in-view.mjs +7 -9
- package/dist/es/utils/use-instant-transition-state.mjs +1 -1
- package/dist/es/utils/use-instant-transition.mjs +6 -9
- package/dist/es/utils/use-is-mounted.mjs +3 -3
- package/dist/es/utils/use-isomorphic-effect.mjs +1 -1
- package/dist/es/utils/use-reduced-motion.mjs +8 -11
- package/dist/es/utils/use-unmount-effect.mjs +1 -1
- package/dist/es/utils/warn-once.mjs +1 -1
- package/dist/es/value/index.mjs +53 -59
- package/dist/es/value/use-combine-values.mjs +3 -3
- package/dist/es/value/use-inverted-scale.mjs +9 -11
- package/dist/es/value/use-motion-template.mjs +5 -9
- package/dist/es/value/use-motion-value.mjs +4 -5
- package/dist/es/value/use-on-change.mjs +4 -4
- package/dist/es/value/use-scroll.mjs +9 -11
- package/dist/es/value/use-spring.mjs +8 -10
- package/dist/es/value/use-time.mjs +2 -2
- package/dist/es/value/use-transform.mjs +6 -10
- package/dist/es/value/use-velocity.mjs +3 -3
- package/dist/es/value/use-will-change/index.mjs +50 -0
- package/dist/es/value/use-will-change/is.mjs +7 -0
- package/dist/es/value/utils/is-motion-value.mjs +1 -1
- package/dist/es/value/utils/resolve-motion-value.mjs +1 -1
- package/dist/framer-motion.dev.js +2134 -2414
- package/dist/framer-motion.js +1 -1
- package/dist/index.d.ts +9 -2
- package/dist/projection.dev.js +1154 -1300
- package/dist/size-rollup-dom-animation.js +1 -1
- package/dist/size-rollup-dom-max.js +1 -1
- package/dist/size-rollup-m.js +1 -1
- package/dist/size-webpack-dom-animation.js +1 -1
- package/dist/size-webpack-dom-max.js +1 -1
- package/dist/size-webpack-m.js +1 -1
- package/dist/three-entry.d.ts +0 -1
- package/package.json +12 -12
package/dist/projection.dev.js
CHANGED
|
@@ -4,71 +4,6 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Projection = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
/******************************************************************************
|
|
8
|
-
Copyright (c) Microsoft Corporation.
|
|
9
|
-
|
|
10
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
-
purpose with or without fee is hereby granted.
|
|
12
|
-
|
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
-
***************************************************************************** */
|
|
21
|
-
|
|
22
|
-
var __assign = function() {
|
|
23
|
-
__assign = Object.assign || function __assign(t) {
|
|
24
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
25
|
-
s = arguments[i];
|
|
26
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
27
|
-
}
|
|
28
|
-
return t;
|
|
29
|
-
};
|
|
30
|
-
return __assign.apply(this, arguments);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
function __rest(s, e) {
|
|
34
|
-
var t = {};
|
|
35
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
36
|
-
t[p] = s[p];
|
|
37
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
38
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
39
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
40
|
-
t[p[i]] = s[p[i]];
|
|
41
|
-
}
|
|
42
|
-
return t;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function __read(o, n) {
|
|
46
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
47
|
-
if (!m) return o;
|
|
48
|
-
var i = m.call(o), r, ar = [], e;
|
|
49
|
-
try {
|
|
50
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
51
|
-
}
|
|
52
|
-
catch (error) { e = { error: error }; }
|
|
53
|
-
finally {
|
|
54
|
-
try {
|
|
55
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
56
|
-
}
|
|
57
|
-
finally { if (e) throw e.error; }
|
|
58
|
-
}
|
|
59
|
-
return ar;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function __spreadArray(to, from, pack) {
|
|
63
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
64
|
-
if (ar || !(i in from)) {
|
|
65
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
66
|
-
ar[i] = from[i];
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
7
|
const defaultTimestep = (1 / 60) * 1000;
|
|
73
8
|
const getCurrentTime = typeof performance !== "undefined"
|
|
74
9
|
? () => performance.now()
|
|
@@ -191,6 +126,33 @@
|
|
|
191
126
|
};
|
|
192
127
|
const getFrameData = () => frame;
|
|
193
128
|
|
|
129
|
+
/******************************************************************************
|
|
130
|
+
Copyright (c) Microsoft Corporation.
|
|
131
|
+
|
|
132
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
133
|
+
purpose with or without fee is hereby granted.
|
|
134
|
+
|
|
135
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
136
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
137
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
138
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
139
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
140
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
141
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
142
|
+
***************************************************************************** */
|
|
143
|
+
|
|
144
|
+
function __rest(s, e) {
|
|
145
|
+
var t = {};
|
|
146
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
147
|
+
t[p] = s[p];
|
|
148
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
149
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
150
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
151
|
+
t[p[i]] = s[p[i]];
|
|
152
|
+
}
|
|
153
|
+
return t;
|
|
154
|
+
}
|
|
155
|
+
|
|
194
156
|
var warning = function () { };
|
|
195
157
|
var invariant = function () { };
|
|
196
158
|
{
|
|
@@ -1212,24 +1174,25 @@
|
|
|
1212
1174
|
}
|
|
1213
1175
|
|
|
1214
1176
|
function addUniqueItem(arr, item) {
|
|
1215
|
-
arr.indexOf(item) === -1
|
|
1177
|
+
if (arr.indexOf(item) === -1)
|
|
1178
|
+
arr.push(item);
|
|
1216
1179
|
}
|
|
1217
1180
|
function removeItem(arr, item) {
|
|
1218
|
-
|
|
1219
|
-
index > -1
|
|
1181
|
+
const index = arr.indexOf(item);
|
|
1182
|
+
if (index > -1)
|
|
1183
|
+
arr.splice(index, 1);
|
|
1220
1184
|
}
|
|
1221
1185
|
|
|
1222
|
-
|
|
1223
|
-
|
|
1186
|
+
class SubscriptionManager {
|
|
1187
|
+
constructor() {
|
|
1224
1188
|
this.subscriptions = [];
|
|
1225
1189
|
}
|
|
1226
|
-
|
|
1227
|
-
var _this = this;
|
|
1190
|
+
add(handler) {
|
|
1228
1191
|
addUniqueItem(this.subscriptions, handler);
|
|
1229
|
-
return
|
|
1230
|
-
}
|
|
1231
|
-
|
|
1232
|
-
|
|
1192
|
+
return () => removeItem(this.subscriptions, handler);
|
|
1193
|
+
}
|
|
1194
|
+
notify(a, b, c) {
|
|
1195
|
+
const numSubscriptions = this.subscriptions.length;
|
|
1233
1196
|
if (!numSubscriptions)
|
|
1234
1197
|
return;
|
|
1235
1198
|
if (numSubscriptions === 1) {
|
|
@@ -1239,26 +1202,25 @@
|
|
|
1239
1202
|
this.subscriptions[0](a, b, c);
|
|
1240
1203
|
}
|
|
1241
1204
|
else {
|
|
1242
|
-
for (
|
|
1205
|
+
for (let i = 0; i < numSubscriptions; i++) {
|
|
1243
1206
|
/**
|
|
1244
1207
|
* Check whether the handler exists before firing as it's possible
|
|
1245
1208
|
* the subscriptions were modified during this loop running.
|
|
1246
1209
|
*/
|
|
1247
|
-
|
|
1210
|
+
const handler = this.subscriptions[i];
|
|
1248
1211
|
handler && handler(a, b, c);
|
|
1249
1212
|
}
|
|
1250
1213
|
}
|
|
1251
|
-
}
|
|
1252
|
-
|
|
1214
|
+
}
|
|
1215
|
+
getSize() {
|
|
1253
1216
|
return this.subscriptions.length;
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1217
|
+
}
|
|
1218
|
+
clear() {
|
|
1256
1219
|
this.subscriptions.length = 0;
|
|
1257
|
-
}
|
|
1258
|
-
|
|
1259
|
-
}());
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1260
1222
|
|
|
1261
|
-
|
|
1223
|
+
const isFloat = (value) => {
|
|
1262
1224
|
return !isNaN(parseFloat(value));
|
|
1263
1225
|
};
|
|
1264
1226
|
/**
|
|
@@ -1266,7 +1228,7 @@
|
|
|
1266
1228
|
*
|
|
1267
1229
|
* @public
|
|
1268
1230
|
*/
|
|
1269
|
-
|
|
1231
|
+
class MotionValue {
|
|
1270
1232
|
/**
|
|
1271
1233
|
* @param init - The initiating value
|
|
1272
1234
|
* @param config - Optional configuration options
|
|
@@ -1275,13 +1237,12 @@
|
|
|
1275
1237
|
*
|
|
1276
1238
|
* @internal
|
|
1277
1239
|
*/
|
|
1278
|
-
|
|
1279
|
-
var _this = this;
|
|
1240
|
+
constructor(init) {
|
|
1280
1241
|
/**
|
|
1281
1242
|
* This will be replaced by the build step with the latest version number.
|
|
1282
1243
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
1283
1244
|
*/
|
|
1284
|
-
this.version = "7.
|
|
1245
|
+
this.version = "7.1.2";
|
|
1285
1246
|
/**
|
|
1286
1247
|
* Duration, in milliseconds, since last updating frame.
|
|
1287
1248
|
*
|
|
@@ -1320,28 +1281,27 @@
|
|
|
1320
1281
|
* @internal
|
|
1321
1282
|
*/
|
|
1322
1283
|
this.canTrackVelocity = false;
|
|
1323
|
-
this.updateAndNotify =
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
_this.current = v;
|
|
1284
|
+
this.updateAndNotify = (v, render = true) => {
|
|
1285
|
+
this.prev = this.current;
|
|
1286
|
+
this.current = v;
|
|
1327
1287
|
// Update timestamp
|
|
1328
|
-
|
|
1329
|
-
if (
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
sync.postRender(
|
|
1288
|
+
const { delta, timestamp } = getFrameData();
|
|
1289
|
+
if (this.lastUpdated !== timestamp) {
|
|
1290
|
+
this.timeDelta = delta;
|
|
1291
|
+
this.lastUpdated = timestamp;
|
|
1292
|
+
sync.postRender(this.scheduleVelocityCheck);
|
|
1333
1293
|
}
|
|
1334
1294
|
// Update update subscribers
|
|
1335
|
-
if (
|
|
1336
|
-
|
|
1295
|
+
if (this.prev !== this.current) {
|
|
1296
|
+
this.updateSubscribers.notify(this.current);
|
|
1337
1297
|
}
|
|
1338
1298
|
// Update velocity subscribers
|
|
1339
|
-
if (
|
|
1340
|
-
|
|
1299
|
+
if (this.velocityUpdateSubscribers.getSize()) {
|
|
1300
|
+
this.velocityUpdateSubscribers.notify(this.getVelocity());
|
|
1341
1301
|
}
|
|
1342
1302
|
// Update render subscribers
|
|
1343
1303
|
if (render) {
|
|
1344
|
-
|
|
1304
|
+
this.renderSubscribers.notify(this.current);
|
|
1345
1305
|
}
|
|
1346
1306
|
};
|
|
1347
1307
|
/**
|
|
@@ -1352,7 +1312,7 @@
|
|
|
1352
1312
|
*
|
|
1353
1313
|
* @internal
|
|
1354
1314
|
*/
|
|
1355
|
-
this.scheduleVelocityCheck =
|
|
1315
|
+
this.scheduleVelocityCheck = () => sync.postRender(this.velocityCheck);
|
|
1356
1316
|
/**
|
|
1357
1317
|
* Updates `prev` with `current` if the value hasn't been updated this frame.
|
|
1358
1318
|
* This ensures velocity calculations return `0`.
|
|
@@ -1362,11 +1322,10 @@
|
|
|
1362
1322
|
*
|
|
1363
1323
|
* @internal
|
|
1364
1324
|
*/
|
|
1365
|
-
this.velocityCheck =
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
_this.velocityUpdateSubscribers.notify(_this.getVelocity());
|
|
1325
|
+
this.velocityCheck = ({ timestamp }) => {
|
|
1326
|
+
if (timestamp !== this.lastUpdated) {
|
|
1327
|
+
this.prev = this.current;
|
|
1328
|
+
this.velocityUpdateSubscribers.notify(this.getVelocity());
|
|
1370
1329
|
}
|
|
1371
1330
|
};
|
|
1372
1331
|
this.hasAnimated = false;
|
|
@@ -1421,12 +1380,12 @@
|
|
|
1421
1380
|
*
|
|
1422
1381
|
* @public
|
|
1423
1382
|
*/
|
|
1424
|
-
|
|
1383
|
+
onChange(subscription) {
|
|
1425
1384
|
return this.updateSubscribers.add(subscription);
|
|
1426
|
-
}
|
|
1427
|
-
|
|
1385
|
+
}
|
|
1386
|
+
clearListeners() {
|
|
1428
1387
|
this.updateSubscribers.clear();
|
|
1429
|
-
}
|
|
1388
|
+
}
|
|
1430
1389
|
/**
|
|
1431
1390
|
* Adds a function that will be notified when the `MotionValue` requests a render.
|
|
1432
1391
|
*
|
|
@@ -1435,19 +1394,19 @@
|
|
|
1435
1394
|
*
|
|
1436
1395
|
* @internal
|
|
1437
1396
|
*/
|
|
1438
|
-
|
|
1397
|
+
onRenderRequest(subscription) {
|
|
1439
1398
|
// Render immediately
|
|
1440
1399
|
subscription(this.get());
|
|
1441
1400
|
return this.renderSubscribers.add(subscription);
|
|
1442
|
-
}
|
|
1401
|
+
}
|
|
1443
1402
|
/**
|
|
1444
1403
|
* Attaches a passive effect to the `MotionValue`.
|
|
1445
1404
|
*
|
|
1446
1405
|
* @internal
|
|
1447
1406
|
*/
|
|
1448
|
-
|
|
1407
|
+
attach(passiveEffect) {
|
|
1449
1408
|
this.passiveEffect = passiveEffect;
|
|
1450
|
-
}
|
|
1409
|
+
}
|
|
1451
1410
|
/**
|
|
1452
1411
|
* Sets the state of the `MotionValue`.
|
|
1453
1412
|
*
|
|
@@ -1463,15 +1422,14 @@
|
|
|
1463
1422
|
*
|
|
1464
1423
|
* @public
|
|
1465
1424
|
*/
|
|
1466
|
-
|
|
1467
|
-
if (render === void 0) { render = true; }
|
|
1425
|
+
set(v, render = true) {
|
|
1468
1426
|
if (!render || !this.passiveEffect) {
|
|
1469
1427
|
this.updateAndNotify(v, render);
|
|
1470
1428
|
}
|
|
1471
1429
|
else {
|
|
1472
1430
|
this.passiveEffect(v, this.updateAndNotify);
|
|
1473
1431
|
}
|
|
1474
|
-
}
|
|
1432
|
+
}
|
|
1475
1433
|
/**
|
|
1476
1434
|
* Returns the latest state of `MotionValue`
|
|
1477
1435
|
*
|
|
@@ -1479,15 +1437,15 @@
|
|
|
1479
1437
|
*
|
|
1480
1438
|
* @public
|
|
1481
1439
|
*/
|
|
1482
|
-
|
|
1440
|
+
get() {
|
|
1483
1441
|
return this.current;
|
|
1484
|
-
}
|
|
1442
|
+
}
|
|
1485
1443
|
/**
|
|
1486
1444
|
* @public
|
|
1487
1445
|
*/
|
|
1488
|
-
|
|
1446
|
+
getPrevious() {
|
|
1489
1447
|
return this.prev;
|
|
1490
|
-
}
|
|
1448
|
+
}
|
|
1491
1449
|
/**
|
|
1492
1450
|
* Returns the latest velocity of `MotionValue`
|
|
1493
1451
|
*
|
|
@@ -1495,14 +1453,14 @@
|
|
|
1495
1453
|
*
|
|
1496
1454
|
* @public
|
|
1497
1455
|
*/
|
|
1498
|
-
|
|
1456
|
+
getVelocity() {
|
|
1499
1457
|
// This could be isFloat(this.prev) && isFloat(this.current), but that would be wasteful
|
|
1500
1458
|
return this.canTrackVelocity
|
|
1501
1459
|
? // These casts could be avoided if parseFloat would be typed better
|
|
1502
1460
|
velocityPerSecond(parseFloat(this.current) -
|
|
1503
1461
|
parseFloat(this.prev), this.timeDelta)
|
|
1504
1462
|
: 0;
|
|
1505
|
-
}
|
|
1463
|
+
}
|
|
1506
1464
|
/**
|
|
1507
1465
|
* Registers a new animation to control this `MotionValue`. Only one
|
|
1508
1466
|
* animation can drive a `MotionValue` at one time.
|
|
@@ -1515,35 +1473,34 @@
|
|
|
1515
1473
|
*
|
|
1516
1474
|
* @internal
|
|
1517
1475
|
*/
|
|
1518
|
-
|
|
1519
|
-
var _this = this;
|
|
1476
|
+
start(animation) {
|
|
1520
1477
|
this.stop();
|
|
1521
|
-
return new Promise(
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
}).then(
|
|
1525
|
-
}
|
|
1478
|
+
return new Promise((resolve) => {
|
|
1479
|
+
this.hasAnimated = true;
|
|
1480
|
+
this.stopAnimation = animation(resolve);
|
|
1481
|
+
}).then(() => this.clearAnimation());
|
|
1482
|
+
}
|
|
1526
1483
|
/**
|
|
1527
1484
|
* Stop the currently active animation.
|
|
1528
1485
|
*
|
|
1529
1486
|
* @public
|
|
1530
1487
|
*/
|
|
1531
|
-
|
|
1488
|
+
stop() {
|
|
1532
1489
|
if (this.stopAnimation)
|
|
1533
1490
|
this.stopAnimation();
|
|
1534
1491
|
this.clearAnimation();
|
|
1535
|
-
}
|
|
1492
|
+
}
|
|
1536
1493
|
/**
|
|
1537
1494
|
* Returns `true` if this value is currently animating.
|
|
1538
1495
|
*
|
|
1539
1496
|
* @public
|
|
1540
1497
|
*/
|
|
1541
|
-
|
|
1498
|
+
isAnimating() {
|
|
1542
1499
|
return !!this.stopAnimation;
|
|
1543
|
-
}
|
|
1544
|
-
|
|
1500
|
+
}
|
|
1501
|
+
clearAnimation() {
|
|
1545
1502
|
this.stopAnimation = null;
|
|
1546
|
-
}
|
|
1503
|
+
}
|
|
1547
1504
|
/**
|
|
1548
1505
|
* Destroy and clean up subscribers to this `MotionValue`.
|
|
1549
1506
|
*
|
|
@@ -1553,18 +1510,17 @@
|
|
|
1553
1510
|
*
|
|
1554
1511
|
* @public
|
|
1555
1512
|
*/
|
|
1556
|
-
|
|
1513
|
+
destroy() {
|
|
1557
1514
|
this.updateSubscribers.clear();
|
|
1558
1515
|
this.renderSubscribers.clear();
|
|
1559
1516
|
this.stop();
|
|
1560
|
-
}
|
|
1561
|
-
|
|
1562
|
-
}());
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1563
1519
|
function motionValue(init) {
|
|
1564
1520
|
return new MotionValue(init);
|
|
1565
1521
|
}
|
|
1566
1522
|
|
|
1567
|
-
|
|
1523
|
+
const isMotionValue = (value) => {
|
|
1568
1524
|
return Boolean(value !== null && typeof value === "object" && value.getVelocity);
|
|
1569
1525
|
};
|
|
1570
1526
|
|
|
@@ -1574,39 +1530,39 @@
|
|
|
1574
1530
|
* @param seconds - Time in seconds.
|
|
1575
1531
|
* @return milliseconds - Converted time in milliseconds.
|
|
1576
1532
|
*/
|
|
1577
|
-
|
|
1533
|
+
const secondsToMilliseconds = (seconds) => seconds * 1000;
|
|
1578
1534
|
|
|
1579
|
-
|
|
1580
|
-
linear
|
|
1581
|
-
easeIn
|
|
1582
|
-
easeInOut
|
|
1583
|
-
easeOut
|
|
1584
|
-
circIn
|
|
1585
|
-
circInOut
|
|
1586
|
-
circOut
|
|
1587
|
-
backIn
|
|
1588
|
-
backInOut
|
|
1589
|
-
backOut
|
|
1590
|
-
anticipate
|
|
1591
|
-
bounceIn
|
|
1592
|
-
bounceInOut
|
|
1593
|
-
bounceOut
|
|
1535
|
+
const easingLookup = {
|
|
1536
|
+
linear,
|
|
1537
|
+
easeIn,
|
|
1538
|
+
easeInOut,
|
|
1539
|
+
easeOut,
|
|
1540
|
+
circIn,
|
|
1541
|
+
circInOut,
|
|
1542
|
+
circOut,
|
|
1543
|
+
backIn,
|
|
1544
|
+
backInOut,
|
|
1545
|
+
backOut,
|
|
1546
|
+
anticipate,
|
|
1547
|
+
bounceIn,
|
|
1548
|
+
bounceInOut,
|
|
1549
|
+
bounceOut,
|
|
1594
1550
|
};
|
|
1595
|
-
|
|
1551
|
+
const easingDefinitionToFunction = (definition) => {
|
|
1596
1552
|
if (Array.isArray(definition)) {
|
|
1597
1553
|
// If cubic bezier definition, create bezier curve
|
|
1598
|
-
invariant(definition.length === 4,
|
|
1599
|
-
|
|
1554
|
+
invariant(definition.length === 4, `Cubic bezier arrays must contain four numerical values.`);
|
|
1555
|
+
const [x1, y1, x2, y2] = definition;
|
|
1600
1556
|
return cubicBezier(x1, y1, x2, y2);
|
|
1601
1557
|
}
|
|
1602
1558
|
else if (typeof definition === "string") {
|
|
1603
1559
|
// Else lookup from table
|
|
1604
|
-
invariant(easingLookup[definition] !== undefined,
|
|
1560
|
+
invariant(easingLookup[definition] !== undefined, `Invalid easing type '${definition}'`);
|
|
1605
1561
|
return easingLookup[definition];
|
|
1606
1562
|
}
|
|
1607
1563
|
return definition;
|
|
1608
1564
|
};
|
|
1609
|
-
|
|
1565
|
+
const isEasingArray = (ease) => {
|
|
1610
1566
|
return Array.isArray(ease) && typeof ease[0] !== "number";
|
|
1611
1567
|
};
|
|
1612
1568
|
|
|
@@ -1619,7 +1575,7 @@
|
|
|
1619
1575
|
*
|
|
1620
1576
|
* @internal
|
|
1621
1577
|
*/
|
|
1622
|
-
|
|
1578
|
+
const isAnimatable = (key, value) => {
|
|
1623
1579
|
// If the list of keys tat might be non-animatable grows, replace with Set
|
|
1624
1580
|
if (key === "zIndex")
|
|
1625
1581
|
return false;
|
|
@@ -1637,33 +1593,33 @@
|
|
|
1637
1593
|
return false;
|
|
1638
1594
|
};
|
|
1639
1595
|
|
|
1640
|
-
|
|
1596
|
+
const isKeyframesTarget = (v) => {
|
|
1641
1597
|
return Array.isArray(v);
|
|
1642
1598
|
};
|
|
1643
1599
|
|
|
1644
|
-
|
|
1600
|
+
const underDampedSpring = () => ({
|
|
1645
1601
|
type: "spring",
|
|
1646
1602
|
stiffness: 500,
|
|
1647
1603
|
damping: 25,
|
|
1648
1604
|
restSpeed: 10,
|
|
1649
|
-
});
|
|
1650
|
-
|
|
1605
|
+
});
|
|
1606
|
+
const criticallyDampedSpring = (to) => ({
|
|
1651
1607
|
type: "spring",
|
|
1652
1608
|
stiffness: 550,
|
|
1653
1609
|
damping: to === 0 ? 2 * Math.sqrt(550) : 30,
|
|
1654
1610
|
restSpeed: 10,
|
|
1655
|
-
});
|
|
1656
|
-
|
|
1611
|
+
});
|
|
1612
|
+
const linearTween = () => ({
|
|
1657
1613
|
type: "keyframes",
|
|
1658
1614
|
ease: "linear",
|
|
1659
1615
|
duration: 0.3,
|
|
1660
|
-
});
|
|
1661
|
-
|
|
1616
|
+
});
|
|
1617
|
+
const keyframes = (values) => ({
|
|
1662
1618
|
type: "keyframes",
|
|
1663
1619
|
duration: 0.8,
|
|
1664
|
-
values
|
|
1665
|
-
});
|
|
1666
|
-
|
|
1620
|
+
values,
|
|
1621
|
+
});
|
|
1622
|
+
const defaultTransitions = {
|
|
1667
1623
|
x: underDampedSpring,
|
|
1668
1624
|
y: underDampedSpring,
|
|
1669
1625
|
z: underDampedSpring,
|
|
@@ -1679,8 +1635,8 @@
|
|
|
1679
1635
|
color: linearTween,
|
|
1680
1636
|
default: criticallyDampedSpring,
|
|
1681
1637
|
};
|
|
1682
|
-
|
|
1683
|
-
|
|
1638
|
+
const getDefaultTransition = (valueKey, to) => {
|
|
1639
|
+
let transitionFactory;
|
|
1684
1640
|
if (isKeyframesTarget(to)) {
|
|
1685
1641
|
transitionFactory = keyframes;
|
|
1686
1642
|
}
|
|
@@ -1688,12 +1644,12 @@
|
|
|
1688
1644
|
transitionFactory =
|
|
1689
1645
|
defaultTransitions[valueKey] || defaultTransitions.default;
|
|
1690
1646
|
}
|
|
1691
|
-
return
|
|
1647
|
+
return Object.assign({ to }, transitionFactory(to));
|
|
1692
1648
|
};
|
|
1693
1649
|
|
|
1694
|
-
|
|
1650
|
+
const int = Object.assign(Object.assign({}, number), { transform: Math.round });
|
|
1695
1651
|
|
|
1696
|
-
|
|
1652
|
+
const numberValueTypes = {
|
|
1697
1653
|
// Border props
|
|
1698
1654
|
borderWidth: px,
|
|
1699
1655
|
borderTopWidth: px,
|
|
@@ -1732,7 +1688,7 @@
|
|
|
1732
1688
|
rotateX: degrees,
|
|
1733
1689
|
rotateY: degrees,
|
|
1734
1690
|
rotateZ: degrees,
|
|
1735
|
-
scale
|
|
1691
|
+
scale,
|
|
1736
1692
|
scaleX: scale,
|
|
1737
1693
|
scaleY: scale,
|
|
1738
1694
|
scaleZ: scale,
|
|
@@ -1763,33 +1719,33 @@
|
|
|
1763
1719
|
/**
|
|
1764
1720
|
* A map of default value types for common values
|
|
1765
1721
|
*/
|
|
1766
|
-
|
|
1722
|
+
const defaultValueTypes = Object.assign(Object.assign({}, numberValueTypes), {
|
|
1767
1723
|
// Color props
|
|
1768
|
-
color
|
|
1724
|
+
color, backgroundColor: color, outlineColor: color, fill: color, stroke: color,
|
|
1769
1725
|
// Border props
|
|
1770
|
-
borderColor: color, borderTopColor: color, borderRightColor: color, borderBottomColor: color, borderLeftColor: color, filter
|
|
1726
|
+
borderColor: color, borderTopColor: color, borderRightColor: color, borderBottomColor: color, borderLeftColor: color, filter, WebkitFilter: filter });
|
|
1771
1727
|
/**
|
|
1772
1728
|
* Gets the default ValueType for the provided value key
|
|
1773
1729
|
*/
|
|
1774
|
-
|
|
1730
|
+
const getDefaultValueType = (key) => defaultValueTypes[key];
|
|
1775
1731
|
|
|
1776
1732
|
function getAnimatableNone(key, value) {
|
|
1777
1733
|
var _a;
|
|
1778
|
-
|
|
1734
|
+
let defaultValueType = getDefaultValueType(key);
|
|
1779
1735
|
if (defaultValueType !== filter)
|
|
1780
1736
|
defaultValueType = complex;
|
|
1781
1737
|
// If value is not recognised as animatable, ie "none", create an animatable version origin based on the target
|
|
1782
1738
|
return (_a = defaultValueType.getAnimatableNone) === null || _a === void 0 ? void 0 : _a.call(defaultValueType, value);
|
|
1783
1739
|
}
|
|
1784
1740
|
|
|
1785
|
-
|
|
1741
|
+
const instantAnimationState = {
|
|
1786
1742
|
current: false,
|
|
1787
1743
|
};
|
|
1788
1744
|
|
|
1789
|
-
|
|
1745
|
+
const isCustomValue = (v) => {
|
|
1790
1746
|
return Boolean(v && typeof v === "object" && v.mix && v.toValue);
|
|
1791
1747
|
};
|
|
1792
|
-
|
|
1748
|
+
const resolveFinalValueInKeyframes = (v) => {
|
|
1793
1749
|
// TODO maybe throw if v.length - 1 is placeholder token?
|
|
1794
1750
|
return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
|
|
1795
1751
|
};
|
|
@@ -1800,16 +1756,16 @@
|
|
|
1800
1756
|
* if any options are left.
|
|
1801
1757
|
*/
|
|
1802
1758
|
function isTransitionDefined(_a) {
|
|
1803
|
-
|
|
1759
|
+
var transition = __rest(_a, ["when", "delay", "delayChildren", "staggerChildren", "staggerDirection", "repeat", "repeatType", "repeatDelay", "from"]);
|
|
1804
1760
|
return !!Object.keys(transition).length;
|
|
1805
1761
|
}
|
|
1806
|
-
|
|
1762
|
+
let legacyRepeatWarning = false;
|
|
1807
1763
|
/**
|
|
1808
1764
|
* Convert Framer Motion's Transition type into Popmotion-compatible options.
|
|
1809
1765
|
*/
|
|
1810
1766
|
function convertTransitionToAnimationOptions(_a) {
|
|
1811
|
-
var
|
|
1812
|
-
|
|
1767
|
+
var { ease, times, yoyo, flip, loop } = _a, transition = __rest(_a, ["ease", "times", "yoyo", "flip", "loop"]);
|
|
1768
|
+
const options = Object.assign({}, transition);
|
|
1813
1769
|
if (times)
|
|
1814
1770
|
options["offset"] = times;
|
|
1815
1771
|
/**
|
|
@@ -1863,12 +1819,12 @@
|
|
|
1863
1819
|
*/
|
|
1864
1820
|
function getDelayFromTransition(transition, key) {
|
|
1865
1821
|
var _a, _b;
|
|
1866
|
-
|
|
1822
|
+
const valueTransition = getValueTransition(transition, key) || {};
|
|
1867
1823
|
return (_b = (_a = valueTransition.delay) !== null && _a !== void 0 ? _a : transition.delay) !== null && _b !== void 0 ? _b : 0;
|
|
1868
1824
|
}
|
|
1869
1825
|
function hydrateKeyframes(options) {
|
|
1870
1826
|
if (Array.isArray(options.to) && options.to[0] === null) {
|
|
1871
|
-
options.to =
|
|
1827
|
+
options.to = [...options.to];
|
|
1872
1828
|
options.to[0] = options.from;
|
|
1873
1829
|
}
|
|
1874
1830
|
return options;
|
|
@@ -1883,18 +1839,18 @@
|
|
|
1883
1839
|
* Get a default transition if none is determined to be defined.
|
|
1884
1840
|
*/
|
|
1885
1841
|
if (!isTransitionDefined(transition)) {
|
|
1886
|
-
transition =
|
|
1842
|
+
transition = Object.assign(Object.assign({}, transition), getDefaultTransition(key, options.to));
|
|
1887
1843
|
}
|
|
1888
|
-
return
|
|
1844
|
+
return Object.assign(Object.assign({}, options), convertTransitionToAnimationOptions(transition));
|
|
1889
1845
|
}
|
|
1890
1846
|
/**
|
|
1891
1847
|
*
|
|
1892
1848
|
*/
|
|
1893
1849
|
function getAnimation(key, value, target, transition, onComplete) {
|
|
1894
1850
|
var _a;
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1851
|
+
const valueTransition = getValueTransition(transition, key);
|
|
1852
|
+
let origin = (_a = valueTransition.from) !== null && _a !== void 0 ? _a : value.get();
|
|
1853
|
+
const isTargetAnimatable = isAnimatable(key, target);
|
|
1898
1854
|
if (origin === "none" && isTargetAnimatable && typeof target === "string") {
|
|
1899
1855
|
/**
|
|
1900
1856
|
* If we're trying to animate from "none", try and get an animatable version
|
|
@@ -1910,24 +1866,24 @@
|
|
|
1910
1866
|
typeof origin === "string") {
|
|
1911
1867
|
target = getZeroUnit(origin);
|
|
1912
1868
|
}
|
|
1913
|
-
|
|
1914
|
-
warning(isOriginAnimatable === isTargetAnimatable,
|
|
1869
|
+
const isOriginAnimatable = isAnimatable(key, origin);
|
|
1870
|
+
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.`);
|
|
1915
1871
|
function start() {
|
|
1916
|
-
|
|
1872
|
+
const options = {
|
|
1917
1873
|
from: origin,
|
|
1918
1874
|
to: target,
|
|
1919
1875
|
velocity: value.getVelocity(),
|
|
1920
|
-
onComplete
|
|
1921
|
-
onUpdate:
|
|
1876
|
+
onComplete,
|
|
1877
|
+
onUpdate: (v) => value.set(v),
|
|
1922
1878
|
};
|
|
1923
1879
|
return valueTransition.type === "inertia" ||
|
|
1924
1880
|
valueTransition.type === "decay"
|
|
1925
|
-
? inertia(
|
|
1926
|
-
: animate$1(
|
|
1881
|
+
? inertia(Object.assign(Object.assign({}, options), valueTransition))
|
|
1882
|
+
: animate$1(Object.assign(Object.assign({}, getPopmotionAnimationOptions(valueTransition, options, key)), { onUpdate: (v) => {
|
|
1927
1883
|
var _a;
|
|
1928
1884
|
options.onUpdate(v);
|
|
1929
1885
|
(_a = valueTransition.onUpdate) === null || _a === void 0 ? void 0 : _a.call(valueTransition, v);
|
|
1930
|
-
}, onComplete:
|
|
1886
|
+
}, onComplete: () => {
|
|
1931
1887
|
var _a;
|
|
1932
1888
|
options.onComplete();
|
|
1933
1889
|
(_a = valueTransition.onComplete) === null || _a === void 0 ? void 0 : _a.call(valueTransition);
|
|
@@ -1935,12 +1891,12 @@
|
|
|
1935
1891
|
}
|
|
1936
1892
|
function set() {
|
|
1937
1893
|
var _a, _b;
|
|
1938
|
-
|
|
1894
|
+
const finalTarget = resolveFinalValueInKeyframes(target);
|
|
1939
1895
|
value.set(finalTarget);
|
|
1940
1896
|
onComplete();
|
|
1941
1897
|
(_a = valueTransition === null || valueTransition === void 0 ? void 0 : valueTransition.onUpdate) === null || _a === void 0 ? void 0 : _a.call(valueTransition, finalTarget);
|
|
1942
1898
|
(_b = valueTransition === null || valueTransition === void 0 ? void 0 : valueTransition.onComplete) === null || _b === void 0 ? void 0 : _b.call(valueTransition);
|
|
1943
|
-
return { stop:
|
|
1899
|
+
return { stop: () => { } };
|
|
1944
1900
|
}
|
|
1945
1901
|
return !isOriginAnimatable ||
|
|
1946
1902
|
!isTargetAnimatable ||
|
|
@@ -1966,24 +1922,23 @@
|
|
|
1966
1922
|
* Start animation on a MotionValue. This function is an interface between
|
|
1967
1923
|
* Framer Motion and Popmotion
|
|
1968
1924
|
*/
|
|
1969
|
-
function startAnimation(key, value, target, transition) {
|
|
1970
|
-
if (transition === void 0) { transition = {}; }
|
|
1925
|
+
function startAnimation(key, value, target, transition = {}) {
|
|
1971
1926
|
if (instantAnimationState.current) {
|
|
1972
1927
|
transition = { type: false };
|
|
1973
1928
|
}
|
|
1974
|
-
return value.start(
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1929
|
+
return value.start((onComplete) => {
|
|
1930
|
+
let delayTimer;
|
|
1931
|
+
let controls;
|
|
1932
|
+
const animation = getAnimation(key, value, target, transition, onComplete);
|
|
1933
|
+
const delay = getDelayFromTransition(transition, key);
|
|
1934
|
+
const start = () => (controls = animation());
|
|
1980
1935
|
if (delay) {
|
|
1981
1936
|
delayTimer = window.setTimeout(start, secondsToMilliseconds(delay));
|
|
1982
1937
|
}
|
|
1983
1938
|
else {
|
|
1984
1939
|
start();
|
|
1985
1940
|
}
|
|
1986
|
-
return
|
|
1941
|
+
return () => {
|
|
1987
1942
|
clearTimeout(delayTimer);
|
|
1988
1943
|
controls === null || controls === void 0 ? void 0 : controls.stop();
|
|
1989
1944
|
};
|
|
@@ -2017,24 +1972,19 @@
|
|
|
2017
1972
|
*
|
|
2018
1973
|
* @public
|
|
2019
1974
|
*/
|
|
2020
|
-
function animate(from, to, transition) {
|
|
2021
|
-
|
|
2022
|
-
var value = isMotionValue(from) ? from : motionValue(from);
|
|
1975
|
+
function animate(from, to, transition = {}) {
|
|
1976
|
+
const value = isMotionValue(from) ? from : motionValue(from);
|
|
2023
1977
|
startAnimation("", value, to, transition);
|
|
2024
1978
|
return {
|
|
2025
|
-
stop:
|
|
2026
|
-
isAnimating:
|
|
1979
|
+
stop: () => value.stop(),
|
|
1980
|
+
isAnimating: () => value.isAnimating(),
|
|
2027
1981
|
};
|
|
2028
1982
|
}
|
|
2029
1983
|
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
};
|
|
2035
|
-
var isPx = function (value) {
|
|
2036
|
-
return typeof value === "number" || px.test(value);
|
|
2037
|
-
};
|
|
1984
|
+
const borders = ["TopLeft", "TopRight", "BottomLeft", "BottomRight"];
|
|
1985
|
+
const numBorders = borders.length;
|
|
1986
|
+
const asNumber = (value) => typeof value === "string" ? parseFloat(value) : value;
|
|
1987
|
+
const isPx = (value) => typeof value === "number" || px.test(value);
|
|
2038
1988
|
function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnlyMember) {
|
|
2039
1989
|
var _a, _b, _c, _d;
|
|
2040
1990
|
if (shouldCrossfadeOpacity) {
|
|
@@ -2050,15 +2000,15 @@
|
|
|
2050
2000
|
/**
|
|
2051
2001
|
* Mix border radius
|
|
2052
2002
|
*/
|
|
2053
|
-
for (
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2003
|
+
for (let i = 0; i < numBorders; i++) {
|
|
2004
|
+
const borderLabel = `border${borders[i]}Radius`;
|
|
2005
|
+
let followRadius = getRadius(follow, borderLabel);
|
|
2006
|
+
let leadRadius = getRadius(lead, borderLabel);
|
|
2057
2007
|
if (followRadius === undefined && leadRadius === undefined)
|
|
2058
2008
|
continue;
|
|
2059
2009
|
followRadius || (followRadius = 0);
|
|
2060
2010
|
leadRadius || (leadRadius = 0);
|
|
2061
|
-
|
|
2011
|
+
const canMix = followRadius === 0 ||
|
|
2062
2012
|
leadRadius === 0 ||
|
|
2063
2013
|
isPx(followRadius) === isPx(leadRadius);
|
|
2064
2014
|
if (canMix) {
|
|
@@ -2105,10 +2055,10 @@
|
|
|
2105
2055
|
// latestLeadValues.backgroundColor as string
|
|
2106
2056
|
// )(p)
|
|
2107
2057
|
// }
|
|
2108
|
-
|
|
2109
|
-
|
|
2058
|
+
const easeCrossfadeIn = compress(0, 0.5, circOut);
|
|
2059
|
+
const easeCrossfadeOut = compress(0.5, 0.95, linear);
|
|
2110
2060
|
function compress(min, max, easing) {
|
|
2111
|
-
return
|
|
2061
|
+
return (p) => {
|
|
2112
2062
|
// Could replace ifs with clamp
|
|
2113
2063
|
if (p < min)
|
|
2114
2064
|
return 0;
|
|
@@ -2140,8 +2090,7 @@
|
|
|
2140
2090
|
function isIdentityScale(scale) {
|
|
2141
2091
|
return scale === undefined || scale === 1;
|
|
2142
2092
|
}
|
|
2143
|
-
function hasScale(
|
|
2144
|
-
var scale = _a.scale, scaleX = _a.scaleX, scaleY = _a.scaleY;
|
|
2093
|
+
function hasScale({ scale, scaleX, scaleY }) {
|
|
2145
2094
|
return (!isIdentityScale(scale) ||
|
|
2146
2095
|
!isIdentityScale(scaleX) ||
|
|
2147
2096
|
!isIdentityScale(scaleY));
|
|
@@ -2163,8 +2112,8 @@
|
|
|
2163
2112
|
* Scales a point based on a factor and an originPoint
|
|
2164
2113
|
*/
|
|
2165
2114
|
function scalePoint(point, scale, originPoint) {
|
|
2166
|
-
|
|
2167
|
-
|
|
2115
|
+
const distanceFromOrigin = point - originPoint;
|
|
2116
|
+
const scaled = scale * distanceFromOrigin;
|
|
2168
2117
|
return originPoint + scaled;
|
|
2169
2118
|
}
|
|
2170
2119
|
/**
|
|
@@ -2179,17 +2128,14 @@
|
|
|
2179
2128
|
/**
|
|
2180
2129
|
* Applies a translate/scale delta to an axis
|
|
2181
2130
|
*/
|
|
2182
|
-
function applyAxisDelta(axis, translate, scale, originPoint, boxScale) {
|
|
2183
|
-
if (translate === void 0) { translate = 0; }
|
|
2184
|
-
if (scale === void 0) { scale = 1; }
|
|
2131
|
+
function applyAxisDelta(axis, translate = 0, scale = 1, originPoint, boxScale) {
|
|
2185
2132
|
axis.min = applyPointDelta(axis.min, translate, scale, originPoint, boxScale);
|
|
2186
2133
|
axis.max = applyPointDelta(axis.max, translate, scale, originPoint, boxScale);
|
|
2187
2134
|
}
|
|
2188
2135
|
/**
|
|
2189
2136
|
* Applies a translate/scale delta to a box
|
|
2190
2137
|
*/
|
|
2191
|
-
function applyBoxDelta(box,
|
|
2192
|
-
var x = _a.x, y = _a.y;
|
|
2138
|
+
function applyBoxDelta(box, { x, y }) {
|
|
2193
2139
|
applyAxisDelta(box.x, x.translate, x.scale, x.originPoint);
|
|
2194
2140
|
applyAxisDelta(box.y, y.translate, y.scale, y.originPoint);
|
|
2195
2141
|
}
|
|
@@ -2199,17 +2145,16 @@
|
|
|
2199
2145
|
*
|
|
2200
2146
|
* This is the final nested loop within updateLayoutDelta for future refactoring
|
|
2201
2147
|
*/
|
|
2202
|
-
function applyTreeDeltas(box, treeScale, treePath, isSharedTransition) {
|
|
2148
|
+
function applyTreeDeltas(box, treeScale, treePath, isSharedTransition = false) {
|
|
2203
2149
|
var _a, _b;
|
|
2204
|
-
|
|
2205
|
-
var treeLength = treePath.length;
|
|
2150
|
+
const treeLength = treePath.length;
|
|
2206
2151
|
if (!treeLength)
|
|
2207
2152
|
return;
|
|
2208
2153
|
// Reset the treeScale
|
|
2209
2154
|
treeScale.x = treeScale.y = 1;
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
for (
|
|
2155
|
+
let node;
|
|
2156
|
+
let delta;
|
|
2157
|
+
for (let i = 0; i < treeLength; i++) {
|
|
2213
2158
|
node = treePath[i];
|
|
2214
2159
|
delta = node.projectionDelta;
|
|
2215
2160
|
if (((_b = (_a = node.instance) === null || _a === void 0 ? void 0 : _a.style) === null || _b === void 0 ? void 0 : _b.display) === "contents")
|
|
@@ -2241,18 +2186,17 @@
|
|
|
2241
2186
|
* This function basically acts as a bridge between a flat motion value map
|
|
2242
2187
|
* and applyAxisDelta
|
|
2243
2188
|
*/
|
|
2244
|
-
function transformAxis(axis, transforms,
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
var originPoint = mix(axis.min, axis.max, axisOrigin);
|
|
2189
|
+
function transformAxis(axis, transforms, [key, scaleKey, originKey]) {
|
|
2190
|
+
const axisOrigin = transforms[originKey] !== undefined ? transforms[originKey] : 0.5;
|
|
2191
|
+
const originPoint = mix(axis.min, axis.max, axisOrigin);
|
|
2248
2192
|
// Apply the axis delta to the final axis
|
|
2249
2193
|
applyAxisDelta(axis, transforms[key], transforms[scaleKey], originPoint, transforms.scale);
|
|
2250
2194
|
}
|
|
2251
2195
|
/**
|
|
2252
2196
|
* The names of the motion values we want to apply as translation, scale and origin.
|
|
2253
2197
|
*/
|
|
2254
|
-
|
|
2255
|
-
|
|
2198
|
+
const xKeys$1 = ["x", "scaleX", "originX"];
|
|
2199
|
+
const yKeys$1 = ["y", "scaleY", "originY"];
|
|
2256
2200
|
/**
|
|
2257
2201
|
* Apply a transform to a box from the latest resolved motion values.
|
|
2258
2202
|
*/
|
|
@@ -2264,13 +2208,10 @@
|
|
|
2264
2208
|
function calcLength(axis) {
|
|
2265
2209
|
return axis.max - axis.min;
|
|
2266
2210
|
}
|
|
2267
|
-
function isNear(value, target, maxDistance) {
|
|
2268
|
-
if (target === void 0) { target = 0; }
|
|
2269
|
-
if (maxDistance === void 0) { maxDistance = 0.01; }
|
|
2211
|
+
function isNear(value, target = 0, maxDistance = 0.01) {
|
|
2270
2212
|
return distance(value, target) < maxDistance;
|
|
2271
2213
|
}
|
|
2272
|
-
function calcAxisDelta(delta, source, target, origin) {
|
|
2273
|
-
if (origin === void 0) { origin = 0.5; }
|
|
2214
|
+
function calcAxisDelta(delta, source, target, origin = 0.5) {
|
|
2274
2215
|
delta.origin = origin;
|
|
2275
2216
|
delta.originPoint = mix(source.min, source.max, delta.origin);
|
|
2276
2217
|
delta.scale = calcLength(target) / calcLength(source);
|
|
@@ -2316,20 +2257,15 @@
|
|
|
2316
2257
|
/**
|
|
2317
2258
|
* Remove a delta from an axis. This is essentially the steps of applyAxisDelta in reverse
|
|
2318
2259
|
*/
|
|
2319
|
-
function removeAxisDelta(axis, translate, scale, origin, boxScale, originAxis, sourceAxis) {
|
|
2320
|
-
if (translate === void 0) { translate = 0; }
|
|
2321
|
-
if (scale === void 0) { scale = 1; }
|
|
2322
|
-
if (origin === void 0) { origin = 0.5; }
|
|
2323
|
-
if (originAxis === void 0) { originAxis = axis; }
|
|
2324
|
-
if (sourceAxis === void 0) { sourceAxis = axis; }
|
|
2260
|
+
function removeAxisDelta(axis, translate = 0, scale = 1, origin = 0.5, boxScale, originAxis = axis, sourceAxis = axis) {
|
|
2325
2261
|
if (percent.test(translate)) {
|
|
2326
2262
|
translate = parseFloat(translate);
|
|
2327
|
-
|
|
2263
|
+
const relativeProgress = mix(sourceAxis.min, sourceAxis.max, translate / 100);
|
|
2328
2264
|
translate = relativeProgress - sourceAxis.min;
|
|
2329
2265
|
}
|
|
2330
2266
|
if (typeof translate !== "number")
|
|
2331
2267
|
return;
|
|
2332
|
-
|
|
2268
|
+
let originPoint = mix(originAxis.min, originAxis.max, origin);
|
|
2333
2269
|
if (axis === originAxis)
|
|
2334
2270
|
originPoint -= translate;
|
|
2335
2271
|
axis.min = removePointDelta(axis.min, translate, scale, originPoint, boxScale);
|
|
@@ -2339,15 +2275,14 @@
|
|
|
2339
2275
|
* Remove a transforms from an axis. This is essentially the steps of applyAxisTransforms in reverse
|
|
2340
2276
|
* and acts as a bridge between motion values and removeAxisDelta
|
|
2341
2277
|
*/
|
|
2342
|
-
function removeAxisTransforms(axis, transforms,
|
|
2343
|
-
var _b = __read(_a, 3), key = _b[0], scaleKey = _b[1], originKey = _b[2];
|
|
2278
|
+
function removeAxisTransforms(axis, transforms, [key, scaleKey, originKey], origin, sourceAxis) {
|
|
2344
2279
|
removeAxisDelta(axis, transforms[key], transforms[scaleKey], transforms[originKey], transforms.scale, origin, sourceAxis);
|
|
2345
2280
|
}
|
|
2346
2281
|
/**
|
|
2347
2282
|
* The names of the motion values we want to apply as translation, scale and origin.
|
|
2348
2283
|
*/
|
|
2349
|
-
|
|
2350
|
-
|
|
2284
|
+
const xKeys = ["x", "scaleX", "originX"];
|
|
2285
|
+
const yKeys = ["y", "scaleY", "originY"];
|
|
2351
2286
|
/**
|
|
2352
2287
|
* Remove a transforms from an box. This is essentially the steps of applyAxisBox in reverse
|
|
2353
2288
|
* and acts as a bridge between motion values and removeAxisDelta
|
|
@@ -2357,21 +2292,21 @@
|
|
|
2357
2292
|
removeAxisTransforms(box.y, transforms, yKeys, originBox === null || originBox === void 0 ? void 0 : originBox.y, sourceBox === null || sourceBox === void 0 ? void 0 : sourceBox.y);
|
|
2358
2293
|
}
|
|
2359
2294
|
|
|
2360
|
-
|
|
2295
|
+
const createAxisDelta = () => ({
|
|
2361
2296
|
translate: 0,
|
|
2362
2297
|
scale: 1,
|
|
2363
2298
|
origin: 0,
|
|
2364
2299
|
originPoint: 0,
|
|
2365
|
-
});
|
|
2366
|
-
|
|
2300
|
+
});
|
|
2301
|
+
const createDelta = () => ({
|
|
2367
2302
|
x: createAxisDelta(),
|
|
2368
2303
|
y: createAxisDelta(),
|
|
2369
|
-
});
|
|
2370
|
-
|
|
2371
|
-
|
|
2304
|
+
});
|
|
2305
|
+
const createAxis = () => ({ min: 0, max: 0 });
|
|
2306
|
+
const createBox = () => ({
|
|
2372
2307
|
x: createAxis(),
|
|
2373
2308
|
y: createAxis(),
|
|
2374
|
-
});
|
|
2309
|
+
});
|
|
2375
2310
|
|
|
2376
2311
|
function isAxisDeltaZero(delta) {
|
|
2377
2312
|
return delta.translate === 0 && delta.scale === 1;
|
|
@@ -2386,36 +2321,36 @@
|
|
|
2386
2321
|
a.y.max === b.y.max);
|
|
2387
2322
|
}
|
|
2388
2323
|
|
|
2389
|
-
|
|
2390
|
-
|
|
2324
|
+
class NodeStack {
|
|
2325
|
+
constructor() {
|
|
2391
2326
|
this.members = [];
|
|
2392
2327
|
}
|
|
2393
|
-
|
|
2328
|
+
add(node) {
|
|
2394
2329
|
addUniqueItem(this.members, node);
|
|
2395
2330
|
node.scheduleRender();
|
|
2396
|
-
}
|
|
2397
|
-
|
|
2331
|
+
}
|
|
2332
|
+
remove(node) {
|
|
2398
2333
|
removeItem(this.members, node);
|
|
2399
2334
|
if (node === this.prevLead) {
|
|
2400
2335
|
this.prevLead = undefined;
|
|
2401
2336
|
}
|
|
2402
2337
|
if (node === this.lead) {
|
|
2403
|
-
|
|
2338
|
+
const prevLead = this.members[this.members.length - 1];
|
|
2404
2339
|
if (prevLead) {
|
|
2405
2340
|
this.promote(prevLead);
|
|
2406
2341
|
}
|
|
2407
2342
|
}
|
|
2408
|
-
}
|
|
2409
|
-
|
|
2410
|
-
|
|
2343
|
+
}
|
|
2344
|
+
relegate(node) {
|
|
2345
|
+
const indexOfNode = this.members.findIndex((member) => node === member);
|
|
2411
2346
|
if (indexOfNode === 0)
|
|
2412
2347
|
return false;
|
|
2413
2348
|
/**
|
|
2414
2349
|
* Find the next projection node that is present
|
|
2415
2350
|
*/
|
|
2416
|
-
|
|
2417
|
-
for (
|
|
2418
|
-
|
|
2351
|
+
let prevLead;
|
|
2352
|
+
for (let i = indexOfNode; i >= 0; i--) {
|
|
2353
|
+
const member = this.members[i];
|
|
2419
2354
|
if (member.isPresent !== false) {
|
|
2420
2355
|
prevLead = member;
|
|
2421
2356
|
break;
|
|
@@ -2428,10 +2363,10 @@
|
|
|
2428
2363
|
else {
|
|
2429
2364
|
return false;
|
|
2430
2365
|
}
|
|
2431
|
-
}
|
|
2432
|
-
|
|
2366
|
+
}
|
|
2367
|
+
promote(node, preserveFollowOpacity) {
|
|
2433
2368
|
var _a;
|
|
2434
|
-
|
|
2369
|
+
const prevLead = this.lead;
|
|
2435
2370
|
if (node === prevLead)
|
|
2436
2371
|
return;
|
|
2437
2372
|
this.prevLead = prevLead;
|
|
@@ -2453,7 +2388,7 @@
|
|
|
2453
2388
|
if ((_a = node.root) === null || _a === void 0 ? void 0 : _a.isUpdating) {
|
|
2454
2389
|
node.isLayoutDirty = true;
|
|
2455
2390
|
}
|
|
2456
|
-
|
|
2391
|
+
const { crossfade } = node.options;
|
|
2457
2392
|
if (crossfade === false) {
|
|
2458
2393
|
prevLead.hide();
|
|
2459
2394
|
}
|
|
@@ -2470,37 +2405,36 @@
|
|
|
2470
2405
|
* - layoutId changes mid animation
|
|
2471
2406
|
*/
|
|
2472
2407
|
}
|
|
2473
|
-
}
|
|
2474
|
-
|
|
2475
|
-
this.members.forEach(
|
|
2408
|
+
}
|
|
2409
|
+
exitAnimationComplete() {
|
|
2410
|
+
this.members.forEach((node) => {
|
|
2476
2411
|
var _a, _b, _c, _d, _e;
|
|
2477
2412
|
(_b = (_a = node.options).onExitComplete) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
2478
2413
|
(_e = (_c = node.resumingFrom) === null || _c === void 0 ? void 0 : (_d = _c.options).onExitComplete) === null || _e === void 0 ? void 0 : _e.call(_d);
|
|
2479
2414
|
});
|
|
2480
|
-
}
|
|
2481
|
-
|
|
2482
|
-
this.members.forEach(
|
|
2415
|
+
}
|
|
2416
|
+
scheduleRender() {
|
|
2417
|
+
this.members.forEach((node) => {
|
|
2483
2418
|
node.instance && node.scheduleRender(false);
|
|
2484
2419
|
});
|
|
2485
|
-
}
|
|
2420
|
+
}
|
|
2486
2421
|
/**
|
|
2487
2422
|
* Clear any leads that have been removed this render to prevent them from being
|
|
2488
2423
|
* used in future animations and to prevent memory leaks
|
|
2489
2424
|
*/
|
|
2490
|
-
|
|
2425
|
+
removeLeadSnapshot() {
|
|
2491
2426
|
if (this.lead && this.lead.snapshot) {
|
|
2492
2427
|
this.lead.snapshot = undefined;
|
|
2493
2428
|
}
|
|
2494
|
-
}
|
|
2495
|
-
|
|
2496
|
-
}());
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2497
2431
|
|
|
2498
|
-
|
|
2432
|
+
const scaleCorrectors = {};
|
|
2499
2433
|
function addScaleCorrector(correctors) {
|
|
2500
2434
|
Object.assign(scaleCorrectors, correctors);
|
|
2501
2435
|
}
|
|
2502
2436
|
|
|
2503
|
-
|
|
2437
|
+
const identityProjection = "translate3d(0px, 0px, 0) scale(1, 1) scale(1, 1)";
|
|
2504
2438
|
function buildProjectionTransform(delta, treeScale, latestTransform) {
|
|
2505
2439
|
/**
|
|
2506
2440
|
* The translations we use to calculate are always relative to the viewport coordinate space.
|
|
@@ -2508,30 +2442,30 @@
|
|
|
2508
2442
|
* For instance if we have a treeScale (the culmination of all parent scales) of 0.5 and we need
|
|
2509
2443
|
* to move an element 100 pixels, we actually need to move it 200 in within that scaled space.
|
|
2510
2444
|
*/
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2445
|
+
const xTranslate = delta.x.translate / treeScale.x;
|
|
2446
|
+
const yTranslate = delta.y.translate / treeScale.y;
|
|
2447
|
+
let transform = `translate3d(${xTranslate}px, ${yTranslate}px, 0) `;
|
|
2514
2448
|
/**
|
|
2515
2449
|
* Apply scale correction for the tree transform.
|
|
2516
2450
|
* This will apply scale to the screen-orientated axes.
|
|
2517
2451
|
*/
|
|
2518
|
-
transform +=
|
|
2452
|
+
transform += `scale(${1 / treeScale.x}, ${1 / treeScale.y}) `;
|
|
2519
2453
|
if (latestTransform) {
|
|
2520
|
-
|
|
2454
|
+
const { rotate, rotateX, rotateY } = latestTransform;
|
|
2521
2455
|
if (rotate)
|
|
2522
|
-
transform +=
|
|
2456
|
+
transform += `rotate(${rotate}deg) `;
|
|
2523
2457
|
if (rotateX)
|
|
2524
|
-
transform +=
|
|
2458
|
+
transform += `rotateX(${rotateX}deg) `;
|
|
2525
2459
|
if (rotateY)
|
|
2526
|
-
transform +=
|
|
2460
|
+
transform += `rotateY(${rotateY}deg) `;
|
|
2527
2461
|
}
|
|
2528
2462
|
/**
|
|
2529
2463
|
* Apply scale to match the size of the element to the size we want it.
|
|
2530
2464
|
* This will apply scale to the element-orientated axes.
|
|
2531
2465
|
*/
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
transform +=
|
|
2466
|
+
const elementScaleX = delta.x.scale * treeScale.x;
|
|
2467
|
+
const elementScaleY = delta.y.scale * treeScale.y;
|
|
2468
|
+
transform += `scale(${elementScaleX}, ${elementScaleY})`;
|
|
2535
2469
|
return transform === identityProjection ? "none" : transform;
|
|
2536
2470
|
}
|
|
2537
2471
|
|
|
@@ -2543,21 +2477,17 @@
|
|
|
2543
2477
|
* A list of all transformable axes. We'll use this list to generated a version
|
|
2544
2478
|
* of each axes for each transform.
|
|
2545
2479
|
*/
|
|
2546
|
-
|
|
2480
|
+
const transformAxes = ["", "X", "Y", "Z"];
|
|
2547
2481
|
/**
|
|
2548
2482
|
* An ordered array of each transformable value. By default, transform values
|
|
2549
2483
|
* will be sorted to this order.
|
|
2550
2484
|
*/
|
|
2551
|
-
|
|
2485
|
+
const order = ["translate", "scale", "rotate", "skew"];
|
|
2552
2486
|
/**
|
|
2553
2487
|
* Generate a list of every possible transform key.
|
|
2554
2488
|
*/
|
|
2555
|
-
|
|
2556
|
-
order.forEach(
|
|
2557
|
-
return transformAxes.forEach(function (axesKey) {
|
|
2558
|
-
return transformProps.push(operationKey + axesKey);
|
|
2559
|
-
});
|
|
2560
|
-
});
|
|
2489
|
+
const transformProps = ["transformPerspective", "x", "y", "z"];
|
|
2490
|
+
order.forEach((operationKey) => transformAxes.forEach((axesKey) => transformProps.push(operationKey + axesKey)));
|
|
2561
2491
|
/**
|
|
2562
2492
|
* A function to use with Array.sort to sort transform keys by their default order.
|
|
2563
2493
|
*/
|
|
@@ -2567,42 +2497,39 @@
|
|
|
2567
2497
|
/**
|
|
2568
2498
|
* A quick lookup for transform props.
|
|
2569
2499
|
*/
|
|
2570
|
-
|
|
2500
|
+
const transformPropSet = new Set(transformProps);
|
|
2571
2501
|
function isTransformProp(key) {
|
|
2572
2502
|
return transformPropSet.has(key);
|
|
2573
2503
|
}
|
|
2574
2504
|
/**
|
|
2575
2505
|
* A quick lookup for transform origin props
|
|
2576
2506
|
*/
|
|
2577
|
-
|
|
2507
|
+
const transformOriginProps = new Set(["originX", "originY", "originZ"]);
|
|
2578
2508
|
function isTransformOriginProp(key) {
|
|
2579
2509
|
return transformOriginProps.has(key);
|
|
2580
2510
|
}
|
|
2581
2511
|
|
|
2582
|
-
|
|
2583
|
-
return a.depth - b.depth;
|
|
2584
|
-
};
|
|
2512
|
+
const compareByDepth = (a, b) => a.depth - b.depth;
|
|
2585
2513
|
|
|
2586
|
-
|
|
2587
|
-
|
|
2514
|
+
class FlatTree {
|
|
2515
|
+
constructor() {
|
|
2588
2516
|
this.children = [];
|
|
2589
2517
|
this.isDirty = false;
|
|
2590
2518
|
}
|
|
2591
|
-
|
|
2519
|
+
add(child) {
|
|
2592
2520
|
addUniqueItem(this.children, child);
|
|
2593
2521
|
this.isDirty = true;
|
|
2594
|
-
}
|
|
2595
|
-
|
|
2522
|
+
}
|
|
2523
|
+
remove(child) {
|
|
2596
2524
|
removeItem(this.children, child);
|
|
2597
2525
|
this.isDirty = true;
|
|
2598
|
-
}
|
|
2599
|
-
|
|
2526
|
+
}
|
|
2527
|
+
forEach(callback) {
|
|
2600
2528
|
this.isDirty && this.children.sort(compareByDepth);
|
|
2601
2529
|
this.isDirty = false;
|
|
2602
2530
|
this.children.forEach(callback);
|
|
2603
|
-
}
|
|
2604
|
-
|
|
2605
|
-
}());
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2606
2533
|
|
|
2607
2534
|
/**
|
|
2608
2535
|
* If the provided value is a MotionValue, this returns the actual value, otherwise just the value itself
|
|
@@ -2610,7 +2537,7 @@
|
|
|
2610
2537
|
* TODO: Remove and move to library
|
|
2611
2538
|
*/
|
|
2612
2539
|
function resolveMotionValue(value) {
|
|
2613
|
-
|
|
2540
|
+
const unwrappedValue = isMotionValue(value) ? value.get() : value;
|
|
2614
2541
|
return isCustomValue(unwrappedValue)
|
|
2615
2542
|
? unwrappedValue.toValue()
|
|
2616
2543
|
: unwrappedValue;
|
|
@@ -2621,7 +2548,7 @@
|
|
|
2621
2548
|
* persist through server requests. If we need instanced states we
|
|
2622
2549
|
* could lazy-init via root.
|
|
2623
2550
|
*/
|
|
2624
|
-
|
|
2551
|
+
const globalProjectionState = {
|
|
2625
2552
|
/**
|
|
2626
2553
|
* Global flag as to whether the tree has animated since the last time
|
|
2627
2554
|
* we resized the window
|
|
@@ -2638,14 +2565,10 @@
|
|
|
2638
2565
|
* We use 1000 as the animation target as 0-1000 maps better to pixels than 0-1
|
|
2639
2566
|
* which has a noticeable difference in spring animations
|
|
2640
2567
|
*/
|
|
2641
|
-
|
|
2642
|
-
function createProjectionNode(
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
function ProjectionNode(id, latestValues, parent) {
|
|
2646
|
-
if (latestValues === void 0) { latestValues = {}; }
|
|
2647
|
-
if (parent === void 0) { parent = defaultParent === null || defaultParent === void 0 ? void 0 : defaultParent(); }
|
|
2648
|
-
var _this = this;
|
|
2568
|
+
const animationTarget = 1000;
|
|
2569
|
+
function createProjectionNode({ attachResizeListener, defaultParent, measureScroll, checkIsScrollRoot, resetTransform, }) {
|
|
2570
|
+
return class ProjectionNode {
|
|
2571
|
+
constructor(id, latestValues = {}, parent = defaultParent === null || defaultParent === void 0 ? void 0 : defaultParent()) {
|
|
2649
2572
|
/**
|
|
2650
2573
|
* A Set containing all this component's children. This is used to iterate
|
|
2651
2574
|
* through the children.
|
|
@@ -2710,15 +2633,15 @@
|
|
|
2710
2633
|
this.eventHandlers = new Map();
|
|
2711
2634
|
// Note: Currently only running on root node
|
|
2712
2635
|
this.potentialNodes = new Map();
|
|
2713
|
-
this.checkUpdateFailed =
|
|
2714
|
-
if (
|
|
2715
|
-
|
|
2716
|
-
|
|
2636
|
+
this.checkUpdateFailed = () => {
|
|
2637
|
+
if (this.isUpdating) {
|
|
2638
|
+
this.isUpdating = false;
|
|
2639
|
+
this.clearAllSnapshots();
|
|
2717
2640
|
}
|
|
2718
2641
|
};
|
|
2719
|
-
this.updateProjection =
|
|
2720
|
-
|
|
2721
|
-
|
|
2642
|
+
this.updateProjection = () => {
|
|
2643
|
+
this.nodes.forEach(resolveTargetDelta);
|
|
2644
|
+
this.nodes.forEach(calcProjection);
|
|
2722
2645
|
};
|
|
2723
2646
|
this.hasProjected = false;
|
|
2724
2647
|
this.isVisible = true;
|
|
@@ -2731,49 +2654,43 @@
|
|
|
2731
2654
|
this.id = id;
|
|
2732
2655
|
this.latestValues = latestValues;
|
|
2733
2656
|
this.root = parent ? parent.root || parent : this;
|
|
2734
|
-
this.path = parent ?
|
|
2657
|
+
this.path = parent ? [...parent.path, parent] : [];
|
|
2735
2658
|
this.parent = parent;
|
|
2736
2659
|
this.depth = parent ? parent.depth + 1 : 0;
|
|
2737
2660
|
id && this.root.registerPotentialNode(id, this);
|
|
2738
|
-
for (
|
|
2661
|
+
for (let i = 0; i < this.path.length; i++) {
|
|
2739
2662
|
this.path[i].shouldResetTransform = true;
|
|
2740
2663
|
}
|
|
2741
2664
|
if (this.root === this)
|
|
2742
2665
|
this.nodes = new FlatTree();
|
|
2743
2666
|
}
|
|
2744
|
-
|
|
2667
|
+
addEventListener(name, handler) {
|
|
2745
2668
|
if (!this.eventHandlers.has(name)) {
|
|
2746
2669
|
this.eventHandlers.set(name, new SubscriptionManager());
|
|
2747
2670
|
}
|
|
2748
2671
|
return this.eventHandlers.get(name).add(handler);
|
|
2749
|
-
}
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
var subscriptionManager = this.eventHandlers.get(name);
|
|
2756
|
-
subscriptionManager === null || subscriptionManager === void 0 ? void 0 : subscriptionManager.notify.apply(subscriptionManager, __spreadArray([], __read(args), false));
|
|
2757
|
-
};
|
|
2758
|
-
ProjectionNode.prototype.hasListeners = function (name) {
|
|
2672
|
+
}
|
|
2673
|
+
notifyListeners(name, ...args) {
|
|
2674
|
+
const subscriptionManager = this.eventHandlers.get(name);
|
|
2675
|
+
subscriptionManager === null || subscriptionManager === void 0 ? void 0 : subscriptionManager.notify(...args);
|
|
2676
|
+
}
|
|
2677
|
+
hasListeners(name) {
|
|
2759
2678
|
return this.eventHandlers.has(name);
|
|
2760
|
-
}
|
|
2761
|
-
|
|
2679
|
+
}
|
|
2680
|
+
registerPotentialNode(id, node) {
|
|
2762
2681
|
this.potentialNodes.set(id, node);
|
|
2763
|
-
}
|
|
2682
|
+
}
|
|
2764
2683
|
/**
|
|
2765
2684
|
* Lifecycles
|
|
2766
2685
|
*/
|
|
2767
|
-
|
|
2768
|
-
var _this = this;
|
|
2686
|
+
mount(instance, isLayoutDirty = false) {
|
|
2769
2687
|
var _a;
|
|
2770
|
-
if (isLayoutDirty === void 0) { isLayoutDirty = false; }
|
|
2771
2688
|
if (this.instance)
|
|
2772
2689
|
return;
|
|
2773
2690
|
this.isSVG =
|
|
2774
2691
|
instance instanceof SVGElement && instance.tagName !== "svg";
|
|
2775
2692
|
this.instance = instance;
|
|
2776
|
-
|
|
2693
|
+
const { layoutId, layout, visualElement } = this.options;
|
|
2777
2694
|
if (visualElement && !visualElement.getInstance()) {
|
|
2778
2695
|
visualElement.mount(instance);
|
|
2779
2696
|
}
|
|
@@ -2784,17 +2701,15 @@
|
|
|
2784
2701
|
this.isLayoutDirty = true;
|
|
2785
2702
|
}
|
|
2786
2703
|
if (attachResizeListener) {
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
clearTimeout(unblockTimeout_1);
|
|
2794
|
-
unblockTimeout_1 = window.setTimeout(resizeUnblockUpdate_1, 250);
|
|
2704
|
+
let unblockTimeout;
|
|
2705
|
+
const resizeUnblockUpdate = () => (this.root.updateBlockedByResize = false);
|
|
2706
|
+
attachResizeListener(instance, () => {
|
|
2707
|
+
this.root.updateBlockedByResize = true;
|
|
2708
|
+
clearTimeout(unblockTimeout);
|
|
2709
|
+
unblockTimeout = window.setTimeout(resizeUnblockUpdate, 250);
|
|
2795
2710
|
if (globalProjectionState.hasAnimatedSinceResize) {
|
|
2796
2711
|
globalProjectionState.hasAnimatedSinceResize = false;
|
|
2797
|
-
|
|
2712
|
+
this.nodes.forEach(finishAnimation);
|
|
2798
2713
|
}
|
|
2799
2714
|
});
|
|
2800
2715
|
}
|
|
@@ -2805,45 +2720,44 @@
|
|
|
2805
2720
|
if (this.options.animate !== false &&
|
|
2806
2721
|
visualElement &&
|
|
2807
2722
|
(layoutId || layout)) {
|
|
2808
|
-
this.addEventListener("didUpdate",
|
|
2809
|
-
var _b, _c, _d, _e
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
_this.relativeTarget = undefined;
|
|
2723
|
+
this.addEventListener("didUpdate", ({ delta, hasLayoutChanged, hasRelativeTargetChanged, layout: newLayout, }) => {
|
|
2724
|
+
var _a, _b, _c, _d, _e;
|
|
2725
|
+
if (this.isTreeAnimationBlocked()) {
|
|
2726
|
+
this.target = undefined;
|
|
2727
|
+
this.relativeTarget = undefined;
|
|
2814
2728
|
return;
|
|
2815
2729
|
}
|
|
2816
2730
|
// TODO: Check here if an animation exists
|
|
2817
|
-
|
|
2818
|
-
|
|
2731
|
+
const layoutTransition = (_b = (_a = this.options.transition) !== null && _a !== void 0 ? _a : visualElement.getDefaultTransition()) !== null && _b !== void 0 ? _b : defaultLayoutTransition;
|
|
2732
|
+
const { onLayoutAnimationStart, onLayoutAnimationComplete, } = visualElement.getProps();
|
|
2819
2733
|
/**
|
|
2820
2734
|
* The target layout of the element might stay the same,
|
|
2821
2735
|
* but its position relative to its parent has changed.
|
|
2822
2736
|
*/
|
|
2823
|
-
|
|
2824
|
-
!boxEquals(
|
|
2737
|
+
const targetChanged = !this.targetLayout ||
|
|
2738
|
+
!boxEquals(this.targetLayout, newLayout) ||
|
|
2825
2739
|
hasRelativeTargetChanged;
|
|
2826
2740
|
/**
|
|
2827
2741
|
* If the layout hasn't seemed to have changed, it might be that the
|
|
2828
2742
|
* element is visually in the same place in the document but its position
|
|
2829
2743
|
* relative to its parent has indeed changed. So here we check for that.
|
|
2830
2744
|
*/
|
|
2831
|
-
|
|
2832
|
-
if (((
|
|
2745
|
+
const hasOnlyRelativeTargetChanged = !hasLayoutChanged && hasRelativeTargetChanged;
|
|
2746
|
+
if (((_c = this.resumeFrom) === null || _c === void 0 ? void 0 : _c.instance) ||
|
|
2833
2747
|
hasOnlyRelativeTargetChanged ||
|
|
2834
2748
|
(hasLayoutChanged &&
|
|
2835
|
-
(targetChanged || !
|
|
2836
|
-
if (
|
|
2837
|
-
|
|
2838
|
-
|
|
2749
|
+
(targetChanged || !this.currentAnimation))) {
|
|
2750
|
+
if (this.resumeFrom) {
|
|
2751
|
+
this.resumingFrom = this.resumeFrom;
|
|
2752
|
+
this.resumingFrom.resumingFrom = undefined;
|
|
2839
2753
|
}
|
|
2840
|
-
|
|
2841
|
-
|
|
2754
|
+
this.setAnimationOrigin(delta, hasOnlyRelativeTargetChanged);
|
|
2755
|
+
const animationOptions = Object.assign(Object.assign({}, getValueTransition(layoutTransition, "layout")), { onPlay: onLayoutAnimationStart, onComplete: onLayoutAnimationComplete });
|
|
2842
2756
|
if (visualElement.shouldReduceMotion) {
|
|
2843
2757
|
animationOptions.delay = 0;
|
|
2844
2758
|
animationOptions.type = false;
|
|
2845
2759
|
}
|
|
2846
|
-
|
|
2760
|
+
this.startAnimation(animationOptions);
|
|
2847
2761
|
}
|
|
2848
2762
|
else {
|
|
2849
2763
|
/**
|
|
@@ -2852,16 +2766,16 @@
|
|
|
2852
2766
|
* that was probably never commited to screen and look like a jumpy box.
|
|
2853
2767
|
*/
|
|
2854
2768
|
if (!hasLayoutChanged &&
|
|
2855
|
-
|
|
2856
|
-
|
|
2769
|
+
this.animationProgress === 0) {
|
|
2770
|
+
this.finishAnimation();
|
|
2857
2771
|
}
|
|
2858
|
-
|
|
2772
|
+
this.isLead() && ((_e = (_d = this.options).onExitComplete) === null || _e === void 0 ? void 0 : _e.call(_d));
|
|
2859
2773
|
}
|
|
2860
|
-
|
|
2774
|
+
this.targetLayout = newLayout;
|
|
2861
2775
|
});
|
|
2862
2776
|
}
|
|
2863
|
-
}
|
|
2864
|
-
|
|
2777
|
+
}
|
|
2778
|
+
unmount() {
|
|
2865
2779
|
var _a, _b;
|
|
2866
2780
|
this.options.layoutId && this.willUpdate();
|
|
2867
2781
|
this.root.nodes.remove(this);
|
|
@@ -2869,34 +2783,33 @@
|
|
|
2869
2783
|
(_b = this.parent) === null || _b === void 0 ? void 0 : _b.children.delete(this);
|
|
2870
2784
|
this.instance = undefined;
|
|
2871
2785
|
cancelSync.preRender(this.updateProjection);
|
|
2872
|
-
}
|
|
2786
|
+
}
|
|
2873
2787
|
// only on the root
|
|
2874
|
-
|
|
2788
|
+
blockUpdate() {
|
|
2875
2789
|
this.updateManuallyBlocked = true;
|
|
2876
|
-
}
|
|
2877
|
-
|
|
2790
|
+
}
|
|
2791
|
+
unblockUpdate() {
|
|
2878
2792
|
this.updateManuallyBlocked = false;
|
|
2879
|
-
}
|
|
2880
|
-
|
|
2793
|
+
}
|
|
2794
|
+
isUpdateBlocked() {
|
|
2881
2795
|
return this.updateManuallyBlocked || this.updateBlockedByResize;
|
|
2882
|
-
}
|
|
2883
|
-
|
|
2796
|
+
}
|
|
2797
|
+
isTreeAnimationBlocked() {
|
|
2884
2798
|
var _a;
|
|
2885
2799
|
return (this.isAnimationBlocked ||
|
|
2886
2800
|
((_a = this.parent) === null || _a === void 0 ? void 0 : _a.isTreeAnimationBlocked()) ||
|
|
2887
2801
|
false);
|
|
2888
|
-
}
|
|
2802
|
+
}
|
|
2889
2803
|
// Note: currently only running on root node
|
|
2890
|
-
|
|
2804
|
+
startUpdate() {
|
|
2891
2805
|
var _a;
|
|
2892
2806
|
if (this.isUpdateBlocked())
|
|
2893
2807
|
return;
|
|
2894
2808
|
this.isUpdating = true;
|
|
2895
2809
|
(_a = this.nodes) === null || _a === void 0 ? void 0 : _a.forEach(resetRotation);
|
|
2896
|
-
}
|
|
2897
|
-
|
|
2810
|
+
}
|
|
2811
|
+
willUpdate(shouldNotifyListeners = true) {
|
|
2898
2812
|
var _a, _b, _c;
|
|
2899
|
-
if (shouldNotifyListeners === void 0) { shouldNotifyListeners = true; }
|
|
2900
2813
|
if (this.root.isUpdateBlocked()) {
|
|
2901
2814
|
(_b = (_a = this.options).onExitComplete) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
2902
2815
|
return;
|
|
@@ -2905,8 +2818,8 @@
|
|
|
2905
2818
|
if (this.isLayoutDirty)
|
|
2906
2819
|
return;
|
|
2907
2820
|
this.isLayoutDirty = true;
|
|
2908
|
-
for (
|
|
2909
|
-
|
|
2821
|
+
for (let i = 0; i < this.path.length; i++) {
|
|
2822
|
+
const node = this.path[i];
|
|
2910
2823
|
node.shouldResetTransform = true;
|
|
2911
2824
|
/**
|
|
2912
2825
|
* TODO: Check we haven't updated the scroll
|
|
@@ -2914,17 +2827,17 @@
|
|
|
2914
2827
|
*/
|
|
2915
2828
|
node.updateScroll();
|
|
2916
2829
|
}
|
|
2917
|
-
|
|
2830
|
+
const { layoutId, layout } = this.options;
|
|
2918
2831
|
if (layoutId === undefined && !layout)
|
|
2919
2832
|
return;
|
|
2920
|
-
|
|
2833
|
+
const transformTemplate = (_c = this.options.visualElement) === null || _c === void 0 ? void 0 : _c.getProps().transformTemplate;
|
|
2921
2834
|
this.prevTransformTemplateValue = transformTemplate === null || transformTemplate === void 0 ? void 0 : transformTemplate(this.latestValues, "");
|
|
2922
2835
|
this.updateSnapshot();
|
|
2923
2836
|
shouldNotifyListeners && this.notifyListeners("willUpdate");
|
|
2924
|
-
}
|
|
2837
|
+
}
|
|
2925
2838
|
// Note: Currently only running on root node
|
|
2926
|
-
|
|
2927
|
-
|
|
2839
|
+
didUpdate() {
|
|
2840
|
+
const updateWasBlocked = this.isUpdateBlocked();
|
|
2928
2841
|
// When doing an instant transition, we skip the layout update,
|
|
2929
2842
|
// but should still clean up the measurements so that the next
|
|
2930
2843
|
// snapshot could be taken correctly.
|
|
@@ -2966,46 +2879,45 @@
|
|
|
2966
2879
|
flushSync.update();
|
|
2967
2880
|
flushSync.preRender();
|
|
2968
2881
|
flushSync.render();
|
|
2969
|
-
}
|
|
2970
|
-
|
|
2882
|
+
}
|
|
2883
|
+
clearAllSnapshots() {
|
|
2971
2884
|
this.nodes.forEach(clearSnapshot);
|
|
2972
2885
|
this.sharedNodes.forEach(removeLeadSnapshots);
|
|
2973
|
-
}
|
|
2974
|
-
|
|
2886
|
+
}
|
|
2887
|
+
scheduleUpdateProjection() {
|
|
2975
2888
|
sync.preRender(this.updateProjection, false, true);
|
|
2976
|
-
}
|
|
2977
|
-
|
|
2978
|
-
var _this = this;
|
|
2889
|
+
}
|
|
2890
|
+
scheduleCheckAfterUnmount() {
|
|
2979
2891
|
/**
|
|
2980
2892
|
* If the unmounting node is in a layoutGroup and did trigger a willUpdate,
|
|
2981
2893
|
* we manually call didUpdate to give a chance to the siblings to animate.
|
|
2982
2894
|
* Otherwise, cleanup all snapshots to prevents future nodes from reusing them.
|
|
2983
2895
|
*/
|
|
2984
|
-
sync.postRender(
|
|
2985
|
-
if (
|
|
2986
|
-
|
|
2896
|
+
sync.postRender(() => {
|
|
2897
|
+
if (this.isLayoutDirty) {
|
|
2898
|
+
this.root.didUpdate();
|
|
2987
2899
|
}
|
|
2988
2900
|
else {
|
|
2989
|
-
|
|
2901
|
+
this.root.checkUpdateFailed();
|
|
2990
2902
|
}
|
|
2991
2903
|
});
|
|
2992
|
-
}
|
|
2904
|
+
}
|
|
2993
2905
|
/**
|
|
2994
2906
|
* Update measurements
|
|
2995
2907
|
*/
|
|
2996
|
-
|
|
2908
|
+
updateSnapshot() {
|
|
2997
2909
|
if (this.snapshot || !this.instance)
|
|
2998
2910
|
return;
|
|
2999
|
-
|
|
3000
|
-
|
|
2911
|
+
const measured = this.measure();
|
|
2912
|
+
const layout = this.removeTransform(this.removeElementScroll(measured));
|
|
3001
2913
|
roundBox(layout);
|
|
3002
2914
|
this.snapshot = {
|
|
3003
|
-
measured
|
|
3004
|
-
layout
|
|
2915
|
+
measured,
|
|
2916
|
+
layout,
|
|
3005
2917
|
latestValues: {},
|
|
3006
2918
|
};
|
|
3007
|
-
}
|
|
3008
|
-
|
|
2919
|
+
}
|
|
2920
|
+
updateLayout() {
|
|
3009
2921
|
var _a;
|
|
3010
2922
|
if (!this.instance)
|
|
3011
2923
|
return;
|
|
@@ -3023,16 +2935,16 @@
|
|
|
3023
2935
|
* up to date.
|
|
3024
2936
|
*/
|
|
3025
2937
|
if (this.resumeFrom && !this.resumeFrom.instance) {
|
|
3026
|
-
for (
|
|
3027
|
-
|
|
2938
|
+
for (let i = 0; i < this.path.length; i++) {
|
|
2939
|
+
const node = this.path[i];
|
|
3028
2940
|
node.updateScroll();
|
|
3029
2941
|
}
|
|
3030
2942
|
}
|
|
3031
|
-
|
|
2943
|
+
const measured = this.measure();
|
|
3032
2944
|
roundBox(measured);
|
|
3033
|
-
|
|
2945
|
+
const prevLayout = this.layout;
|
|
3034
2946
|
this.layout = {
|
|
3035
|
-
measured
|
|
2947
|
+
measured,
|
|
3036
2948
|
actual: this.removeElementScroll(measured),
|
|
3037
2949
|
};
|
|
3038
2950
|
this.layoutCorrected = createBox();
|
|
@@ -3040,22 +2952,22 @@
|
|
|
3040
2952
|
this.projectionDelta = undefined;
|
|
3041
2953
|
this.notifyListeners("measure", this.layout.actual);
|
|
3042
2954
|
(_a = this.options.visualElement) === null || _a === void 0 ? void 0 : _a.notifyLayoutMeasure(this.layout.actual, prevLayout === null || prevLayout === void 0 ? void 0 : prevLayout.actual);
|
|
3043
|
-
}
|
|
3044
|
-
|
|
2955
|
+
}
|
|
2956
|
+
updateScroll() {
|
|
3045
2957
|
if (this.options.layoutScroll && this.instance) {
|
|
3046
2958
|
this.isScrollRoot = checkIsScrollRoot(this.instance);
|
|
3047
2959
|
this.scroll = measureScroll(this.instance);
|
|
3048
2960
|
}
|
|
3049
|
-
}
|
|
3050
|
-
|
|
2961
|
+
}
|
|
2962
|
+
resetTransform() {
|
|
3051
2963
|
var _a;
|
|
3052
2964
|
if (!resetTransform)
|
|
3053
2965
|
return;
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
2966
|
+
const isResetRequested = this.isLayoutDirty || this.shouldResetTransform;
|
|
2967
|
+
const hasProjection = this.projectionDelta && !isDeltaZero(this.projectionDelta);
|
|
2968
|
+
const transformTemplate = (_a = this.options.visualElement) === null || _a === void 0 ? void 0 : _a.getProps().transformTemplate;
|
|
2969
|
+
const transformTemplateValue = transformTemplate === null || transformTemplate === void 0 ? void 0 : transformTemplate(this.latestValues, "");
|
|
2970
|
+
const transformTemplateHasChanged = transformTemplateValue !== this.prevTransformTemplateValue;
|
|
3059
2971
|
if (isResetRequested &&
|
|
3060
2972
|
(hasProjection ||
|
|
3061
2973
|
hasTransform(this.latestValues) ||
|
|
@@ -3064,38 +2976,38 @@
|
|
|
3064
2976
|
this.shouldResetTransform = false;
|
|
3065
2977
|
this.scheduleRender();
|
|
3066
2978
|
}
|
|
3067
|
-
}
|
|
3068
|
-
|
|
3069
|
-
|
|
2979
|
+
}
|
|
2980
|
+
measure() {
|
|
2981
|
+
const { visualElement } = this.options;
|
|
3070
2982
|
if (!visualElement)
|
|
3071
2983
|
return createBox();
|
|
3072
|
-
|
|
2984
|
+
const box = visualElement.measureViewportBox();
|
|
3073
2985
|
// Remove viewport scroll to give page-relative coordinates
|
|
3074
|
-
|
|
2986
|
+
const { scroll } = this.root;
|
|
3075
2987
|
if (scroll) {
|
|
3076
2988
|
translateAxis(box.x, scroll.x);
|
|
3077
2989
|
translateAxis(box.y, scroll.y);
|
|
3078
2990
|
}
|
|
3079
2991
|
return box;
|
|
3080
|
-
}
|
|
3081
|
-
|
|
3082
|
-
|
|
2992
|
+
}
|
|
2993
|
+
removeElementScroll(box) {
|
|
2994
|
+
const boxWithoutScroll = createBox();
|
|
3083
2995
|
copyBoxInto(boxWithoutScroll, box);
|
|
3084
2996
|
/**
|
|
3085
2997
|
* Performance TODO: Keep a cumulative scroll offset down the tree
|
|
3086
2998
|
* rather than loop back up the path.
|
|
3087
2999
|
*/
|
|
3088
|
-
for (
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
if (node !== this.root &&
|
|
3000
|
+
for (let i = 0; i < this.path.length; i++) {
|
|
3001
|
+
const node = this.path[i];
|
|
3002
|
+
const { scroll, options, isScrollRoot } = node;
|
|
3003
|
+
if (node !== this.root && scroll && options.layoutScroll) {
|
|
3092
3004
|
/**
|
|
3093
3005
|
* If this is a new scroll root, we want to remove all previous scrolls
|
|
3094
3006
|
* from the viewport box.
|
|
3095
3007
|
*/
|
|
3096
3008
|
if (isScrollRoot) {
|
|
3097
3009
|
copyBoxInto(boxWithoutScroll, box);
|
|
3098
|
-
|
|
3010
|
+
const { scroll: rootScroll } = this.root;
|
|
3099
3011
|
/**
|
|
3100
3012
|
* Undo the application of page scroll that was originally added
|
|
3101
3013
|
* to the measured bounding box.
|
|
@@ -3105,18 +3017,17 @@
|
|
|
3105
3017
|
translateAxis(boxWithoutScroll.y, -rootScroll.y);
|
|
3106
3018
|
}
|
|
3107
3019
|
}
|
|
3108
|
-
translateAxis(boxWithoutScroll.x,
|
|
3109
|
-
translateAxis(boxWithoutScroll.y,
|
|
3020
|
+
translateAxis(boxWithoutScroll.x, scroll.x);
|
|
3021
|
+
translateAxis(boxWithoutScroll.y, scroll.y);
|
|
3110
3022
|
}
|
|
3111
3023
|
}
|
|
3112
3024
|
return boxWithoutScroll;
|
|
3113
|
-
}
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
var withTransforms = createBox();
|
|
3025
|
+
}
|
|
3026
|
+
applyTransform(box, transformOnly = false) {
|
|
3027
|
+
const withTransforms = createBox();
|
|
3117
3028
|
copyBoxInto(withTransforms, box);
|
|
3118
|
-
for (
|
|
3119
|
-
|
|
3029
|
+
for (let i = 0; i < this.path.length; i++) {
|
|
3030
|
+
const node = this.path[i];
|
|
3120
3031
|
if (!transformOnly &&
|
|
3121
3032
|
node.options.layoutScroll &&
|
|
3122
3033
|
node.scroll &&
|
|
@@ -3134,20 +3045,20 @@
|
|
|
3134
3045
|
transformBox(withTransforms, this.latestValues);
|
|
3135
3046
|
}
|
|
3136
3047
|
return withTransforms;
|
|
3137
|
-
}
|
|
3138
|
-
|
|
3048
|
+
}
|
|
3049
|
+
removeTransform(box) {
|
|
3139
3050
|
var _a;
|
|
3140
|
-
|
|
3051
|
+
const boxWithoutTransform = createBox();
|
|
3141
3052
|
copyBoxInto(boxWithoutTransform, box);
|
|
3142
|
-
for (
|
|
3143
|
-
|
|
3053
|
+
for (let i = 0; i < this.path.length; i++) {
|
|
3054
|
+
const node = this.path[i];
|
|
3144
3055
|
if (!node.instance)
|
|
3145
3056
|
continue;
|
|
3146
3057
|
if (!hasTransform(node.latestValues))
|
|
3147
3058
|
continue;
|
|
3148
3059
|
hasScale(node.latestValues) && node.updateSnapshot();
|
|
3149
|
-
|
|
3150
|
-
|
|
3060
|
+
const sourceBox = createBox();
|
|
3061
|
+
const nodeBox = node.measure();
|
|
3151
3062
|
copyBoxInto(sourceBox, nodeBox);
|
|
3152
3063
|
removeBoxTransforms(boxWithoutTransform, node.latestValues, (_a = node.snapshot) === null || _a === void 0 ? void 0 : _a.layout, sourceBox);
|
|
3153
3064
|
}
|
|
@@ -3155,19 +3066,19 @@
|
|
|
3155
3066
|
removeBoxTransforms(boxWithoutTransform, this.latestValues);
|
|
3156
3067
|
}
|
|
3157
3068
|
return boxWithoutTransform;
|
|
3158
|
-
}
|
|
3069
|
+
}
|
|
3159
3070
|
/**
|
|
3160
3071
|
*
|
|
3161
3072
|
*/
|
|
3162
|
-
|
|
3073
|
+
setTargetDelta(delta) {
|
|
3163
3074
|
this.targetDelta = delta;
|
|
3164
3075
|
this.root.scheduleUpdateProjection();
|
|
3165
|
-
}
|
|
3166
|
-
|
|
3076
|
+
}
|
|
3077
|
+
setOptions(options) {
|
|
3167
3078
|
var _a;
|
|
3168
|
-
this.options =
|
|
3169
|
-
}
|
|
3170
|
-
|
|
3079
|
+
this.options = Object.assign(Object.assign(Object.assign({}, this.options), options), { crossfade: (_a = options.crossfade) !== null && _a !== void 0 ? _a : true });
|
|
3080
|
+
}
|
|
3081
|
+
clearMeasurements() {
|
|
3171
3082
|
this.scroll = undefined;
|
|
3172
3083
|
this.layout = undefined;
|
|
3173
3084
|
this.snapshot = undefined;
|
|
@@ -3175,13 +3086,13 @@
|
|
|
3175
3086
|
this.targetDelta = undefined;
|
|
3176
3087
|
this.target = undefined;
|
|
3177
3088
|
this.isLayoutDirty = false;
|
|
3178
|
-
}
|
|
3089
|
+
}
|
|
3179
3090
|
/**
|
|
3180
3091
|
* Frame calculations
|
|
3181
3092
|
*/
|
|
3182
|
-
|
|
3093
|
+
resolveTargetDelta() {
|
|
3183
3094
|
var _a;
|
|
3184
|
-
|
|
3095
|
+
const { layout, layoutId } = this.options;
|
|
3185
3096
|
/**
|
|
3186
3097
|
* If we have no layout, we can't perform projection, so early return
|
|
3187
3098
|
*/
|
|
@@ -3260,8 +3171,8 @@
|
|
|
3260
3171
|
copyBoxInto(this.relativeTarget, this.relativeTargetOrigin);
|
|
3261
3172
|
}
|
|
3262
3173
|
}
|
|
3263
|
-
}
|
|
3264
|
-
|
|
3174
|
+
}
|
|
3175
|
+
getClosestProjectingParent() {
|
|
3265
3176
|
if (!this.parent || hasTransform(this.parent.latestValues))
|
|
3266
3177
|
return undefined;
|
|
3267
3178
|
if ((this.parent.relativeTarget || this.parent.targetDelta) &&
|
|
@@ -3271,10 +3182,10 @@
|
|
|
3271
3182
|
else {
|
|
3272
3183
|
return this.parent.getClosestProjectingParent();
|
|
3273
3184
|
}
|
|
3274
|
-
}
|
|
3275
|
-
|
|
3185
|
+
}
|
|
3186
|
+
calcProjection() {
|
|
3276
3187
|
var _a;
|
|
3277
|
-
|
|
3188
|
+
const { layout, layoutId } = this.options;
|
|
3278
3189
|
/**
|
|
3279
3190
|
* If this section of the tree isn't animating we can
|
|
3280
3191
|
* delete our target sources for the following frame.
|
|
@@ -3287,7 +3198,7 @@
|
|
|
3287
3198
|
}
|
|
3288
3199
|
if (!this.layout || !(layout || layoutId))
|
|
3289
3200
|
return;
|
|
3290
|
-
|
|
3201
|
+
const lead = this.getLead();
|
|
3291
3202
|
/**
|
|
3292
3203
|
* Reset the corrected box with the latest values from box, as we're then going
|
|
3293
3204
|
* to perform mutative operations on it.
|
|
@@ -3298,16 +3209,16 @@
|
|
|
3298
3209
|
* is the layout box, as it will appear on screen as a result of the transforms of its parents.
|
|
3299
3210
|
*/
|
|
3300
3211
|
applyTreeDeltas(this.layoutCorrected, this.treeScale, this.path, Boolean(this.resumingFrom) || this !== lead);
|
|
3301
|
-
|
|
3212
|
+
const { target } = lead;
|
|
3302
3213
|
if (!target)
|
|
3303
3214
|
return;
|
|
3304
3215
|
if (!this.projectionDelta) {
|
|
3305
3216
|
this.projectionDelta = createDelta();
|
|
3306
3217
|
this.projectionDeltaWithTransform = createDelta();
|
|
3307
3218
|
}
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3219
|
+
const prevTreeScaleX = this.treeScale.x;
|
|
3220
|
+
const prevTreeScaleY = this.treeScale.y;
|
|
3221
|
+
const prevProjectionTransform = this.projectionTransform;
|
|
3311
3222
|
/**
|
|
3312
3223
|
* Update the delta between the corrected box and the target box before user-set transforms were applied.
|
|
3313
3224
|
* This will allow us to calculate the corrected borderRadius and boxShadow to compensate
|
|
@@ -3326,67 +3237,63 @@
|
|
|
3326
3237
|
this.scheduleRender();
|
|
3327
3238
|
this.notifyListeners("projectionUpdate", target);
|
|
3328
3239
|
}
|
|
3329
|
-
}
|
|
3330
|
-
|
|
3240
|
+
}
|
|
3241
|
+
hide() {
|
|
3331
3242
|
this.isVisible = false;
|
|
3332
3243
|
// TODO: Schedule render
|
|
3333
|
-
}
|
|
3334
|
-
|
|
3244
|
+
}
|
|
3245
|
+
show() {
|
|
3335
3246
|
this.isVisible = true;
|
|
3336
3247
|
// TODO: Schedule render
|
|
3337
|
-
}
|
|
3338
|
-
|
|
3248
|
+
}
|
|
3249
|
+
scheduleRender(notifyAll = true) {
|
|
3339
3250
|
var _a, _b, _c;
|
|
3340
|
-
if (notifyAll === void 0) { notifyAll = true; }
|
|
3341
3251
|
(_b = (_a = this.options).scheduleRender) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
3342
3252
|
notifyAll && ((_c = this.getStack()) === null || _c === void 0 ? void 0 : _c.scheduleRender());
|
|
3343
3253
|
if (this.resumingFrom && !this.resumingFrom.instance) {
|
|
3344
3254
|
this.resumingFrom = undefined;
|
|
3345
3255
|
}
|
|
3346
|
-
}
|
|
3347
|
-
|
|
3348
|
-
var _this = this;
|
|
3256
|
+
}
|
|
3257
|
+
setAnimationOrigin(delta, hasOnlyRelativeTargetChanged = false) {
|
|
3349
3258
|
var _a;
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
var targetDelta = createDelta();
|
|
3259
|
+
const snapshot = this.snapshot;
|
|
3260
|
+
const snapshotLatestValues = (snapshot === null || snapshot === void 0 ? void 0 : snapshot.latestValues) || {};
|
|
3261
|
+
const mixedValues = Object.assign({}, this.latestValues);
|
|
3262
|
+
const targetDelta = createDelta();
|
|
3355
3263
|
this.relativeTarget = this.relativeTargetOrigin = undefined;
|
|
3356
3264
|
this.attemptToResolveRelativeTarget = !hasOnlyRelativeTargetChanged;
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3265
|
+
const relativeLayout = createBox();
|
|
3266
|
+
const isSharedLayoutAnimation = snapshot === null || snapshot === void 0 ? void 0 : snapshot.isShared;
|
|
3267
|
+
const isOnlyMember = (((_a = this.getStack()) === null || _a === void 0 ? void 0 : _a.members.length) || 0) <= 1;
|
|
3268
|
+
const shouldCrossfadeOpacity = Boolean(isSharedLayoutAnimation &&
|
|
3361
3269
|
!isOnlyMember &&
|
|
3362
3270
|
this.options.crossfade === true &&
|
|
3363
3271
|
!this.path.some(hasOpacityCrossfade));
|
|
3364
3272
|
this.animationProgress = 0;
|
|
3365
|
-
this.mixTargetDelta =
|
|
3273
|
+
this.mixTargetDelta = (latest) => {
|
|
3366
3274
|
var _a;
|
|
3367
|
-
|
|
3275
|
+
const progress = latest / 1000;
|
|
3368
3276
|
mixAxisDelta(targetDelta.x, delta.x, progress);
|
|
3369
3277
|
mixAxisDelta(targetDelta.y, delta.y, progress);
|
|
3370
|
-
|
|
3371
|
-
if (
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
((_a =
|
|
3375
|
-
calcRelativePosition(relativeLayout,
|
|
3376
|
-
mixBox(
|
|
3278
|
+
this.setTargetDelta(targetDelta);
|
|
3279
|
+
if (this.relativeTarget &&
|
|
3280
|
+
this.relativeTargetOrigin &&
|
|
3281
|
+
this.layout &&
|
|
3282
|
+
((_a = this.relativeParent) === null || _a === void 0 ? void 0 : _a.layout)) {
|
|
3283
|
+
calcRelativePosition(relativeLayout, this.layout.actual, this.relativeParent.layout.actual);
|
|
3284
|
+
mixBox(this.relativeTarget, this.relativeTargetOrigin, relativeLayout, progress);
|
|
3377
3285
|
}
|
|
3378
3286
|
if (isSharedLayoutAnimation) {
|
|
3379
|
-
|
|
3380
|
-
mixValues(mixedValues, snapshotLatestValues,
|
|
3287
|
+
this.animationValues = mixedValues;
|
|
3288
|
+
mixValues(mixedValues, snapshotLatestValues, this.latestValues, progress, shouldCrossfadeOpacity, isOnlyMember);
|
|
3381
3289
|
}
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3290
|
+
this.root.scheduleUpdateProjection();
|
|
3291
|
+
this.scheduleRender();
|
|
3292
|
+
this.animationProgress = progress;
|
|
3385
3293
|
};
|
|
3386
3294
|
this.mixTargetDelta(0);
|
|
3387
|
-
}
|
|
3388
|
-
|
|
3389
|
-
var _this = this;
|
|
3295
|
+
}
|
|
3296
|
+
startAnimation(options) {
|
|
3390
3297
|
var _a, _b;
|
|
3391
3298
|
this.notifyListeners("animationStart");
|
|
3392
3299
|
(_a = this.currentAnimation) === null || _a === void 0 ? void 0 : _a.stop();
|
|
@@ -3402,24 +3309,24 @@
|
|
|
3402
3309
|
* where the target is the same as when the animation started, so we can
|
|
3403
3310
|
* calculate the relative positions correctly for instant transitions.
|
|
3404
3311
|
*/
|
|
3405
|
-
this.pendingAnimation = sync.update(
|
|
3312
|
+
this.pendingAnimation = sync.update(() => {
|
|
3406
3313
|
globalProjectionState.hasAnimatedSinceResize = true;
|
|
3407
|
-
|
|
3314
|
+
this.currentAnimation = animate(0, animationTarget, Object.assign(Object.assign({}, options), { onUpdate: (latest) => {
|
|
3408
3315
|
var _a;
|
|
3409
|
-
|
|
3316
|
+
this.mixTargetDelta(latest);
|
|
3410
3317
|
(_a = options.onUpdate) === null || _a === void 0 ? void 0 : _a.call(options, latest);
|
|
3411
|
-
}, onComplete:
|
|
3318
|
+
}, onComplete: () => {
|
|
3412
3319
|
var _a;
|
|
3413
3320
|
(_a = options.onComplete) === null || _a === void 0 ? void 0 : _a.call(options);
|
|
3414
|
-
|
|
3321
|
+
this.completeAnimation();
|
|
3415
3322
|
} }));
|
|
3416
|
-
if (
|
|
3417
|
-
|
|
3323
|
+
if (this.resumingFrom) {
|
|
3324
|
+
this.resumingFrom.currentAnimation = this.currentAnimation;
|
|
3418
3325
|
}
|
|
3419
|
-
|
|
3326
|
+
this.pendingAnimation = undefined;
|
|
3420
3327
|
});
|
|
3421
|
-
}
|
|
3422
|
-
|
|
3328
|
+
}
|
|
3329
|
+
completeAnimation() {
|
|
3423
3330
|
var _a;
|
|
3424
3331
|
if (this.resumingFrom) {
|
|
3425
3332
|
this.resumingFrom.currentAnimation = undefined;
|
|
@@ -3431,17 +3338,17 @@
|
|
|
3431
3338
|
this.animationValues =
|
|
3432
3339
|
undefined;
|
|
3433
3340
|
this.notifyListeners("animationComplete");
|
|
3434
|
-
}
|
|
3435
|
-
|
|
3341
|
+
}
|
|
3342
|
+
finishAnimation() {
|
|
3436
3343
|
var _a;
|
|
3437
3344
|
if (this.currentAnimation) {
|
|
3438
3345
|
(_a = this.mixTargetDelta) === null || _a === void 0 ? void 0 : _a.call(this, animationTarget);
|
|
3439
3346
|
this.currentAnimation.stop();
|
|
3440
3347
|
}
|
|
3441
3348
|
this.completeAnimation();
|
|
3442
|
-
}
|
|
3443
|
-
|
|
3444
|
-
|
|
3349
|
+
}
|
|
3350
|
+
applyTransformsToTarget() {
|
|
3351
|
+
const { targetWithTransforms, target, layout, latestValues } = this.getLead();
|
|
3445
3352
|
if (!targetWithTransforms || !target || !layout)
|
|
3446
3353
|
return;
|
|
3447
3354
|
copyBoxInto(targetWithTransforms, target);
|
|
@@ -3458,41 +3365,40 @@
|
|
|
3458
3365
|
* into the desired bounding box.
|
|
3459
3366
|
*/
|
|
3460
3367
|
calcBoxDelta(this.projectionDeltaWithTransform, this.layoutCorrected, targetWithTransforms, latestValues);
|
|
3461
|
-
}
|
|
3462
|
-
|
|
3368
|
+
}
|
|
3369
|
+
registerSharedNode(layoutId, node) {
|
|
3463
3370
|
var _a, _b, _c;
|
|
3464
3371
|
if (!this.sharedNodes.has(layoutId)) {
|
|
3465
3372
|
this.sharedNodes.set(layoutId, new NodeStack());
|
|
3466
3373
|
}
|
|
3467
|
-
|
|
3374
|
+
const stack = this.sharedNodes.get(layoutId);
|
|
3468
3375
|
stack.add(node);
|
|
3469
3376
|
node.promote({
|
|
3470
3377
|
transition: (_a = node.options.initialPromotionConfig) === null || _a === void 0 ? void 0 : _a.transition,
|
|
3471
3378
|
preserveFollowOpacity: (_c = (_b = node.options.initialPromotionConfig) === null || _b === void 0 ? void 0 : _b.shouldPreserveFollowOpacity) === null || _c === void 0 ? void 0 : _c.call(_b, node),
|
|
3472
3379
|
});
|
|
3473
|
-
}
|
|
3474
|
-
|
|
3475
|
-
|
|
3380
|
+
}
|
|
3381
|
+
isLead() {
|
|
3382
|
+
const stack = this.getStack();
|
|
3476
3383
|
return stack ? stack.lead === this : true;
|
|
3477
|
-
}
|
|
3478
|
-
|
|
3384
|
+
}
|
|
3385
|
+
getLead() {
|
|
3479
3386
|
var _a;
|
|
3480
|
-
|
|
3387
|
+
const { layoutId } = this.options;
|
|
3481
3388
|
return layoutId ? ((_a = this.getStack()) === null || _a === void 0 ? void 0 : _a.lead) || this : this;
|
|
3482
|
-
}
|
|
3483
|
-
|
|
3389
|
+
}
|
|
3390
|
+
getPrevLead() {
|
|
3484
3391
|
var _a;
|
|
3485
|
-
|
|
3392
|
+
const { layoutId } = this.options;
|
|
3486
3393
|
return layoutId ? (_a = this.getStack()) === null || _a === void 0 ? void 0 : _a.prevLead : undefined;
|
|
3487
|
-
}
|
|
3488
|
-
|
|
3489
|
-
|
|
3394
|
+
}
|
|
3395
|
+
getStack() {
|
|
3396
|
+
const { layoutId } = this.options;
|
|
3490
3397
|
if (layoutId)
|
|
3491
3398
|
return this.root.sharedNodes.get(layoutId);
|
|
3492
|
-
}
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
var stack = this.getStack();
|
|
3399
|
+
}
|
|
3400
|
+
promote({ needsReset, transition, preserveFollowOpacity, } = {}) {
|
|
3401
|
+
const stack = this.getStack();
|
|
3496
3402
|
if (stack)
|
|
3497
3403
|
stack.promote(this, preserveFollowOpacity);
|
|
3498
3404
|
if (needsReset) {
|
|
@@ -3500,29 +3406,29 @@
|
|
|
3500
3406
|
this.needsReset = true;
|
|
3501
3407
|
}
|
|
3502
3408
|
if (transition)
|
|
3503
|
-
this.setOptions({ transition
|
|
3504
|
-
}
|
|
3505
|
-
|
|
3506
|
-
|
|
3409
|
+
this.setOptions({ transition });
|
|
3410
|
+
}
|
|
3411
|
+
relegate() {
|
|
3412
|
+
const stack = this.getStack();
|
|
3507
3413
|
if (stack) {
|
|
3508
3414
|
return stack.relegate(this);
|
|
3509
3415
|
}
|
|
3510
3416
|
else {
|
|
3511
3417
|
return false;
|
|
3512
3418
|
}
|
|
3513
|
-
}
|
|
3514
|
-
|
|
3515
|
-
|
|
3419
|
+
}
|
|
3420
|
+
resetRotation() {
|
|
3421
|
+
const { visualElement } = this.options;
|
|
3516
3422
|
if (!visualElement)
|
|
3517
3423
|
return;
|
|
3518
3424
|
// If there's no detected rotation values, we can early return without a forced render.
|
|
3519
|
-
|
|
3425
|
+
let hasRotate = false;
|
|
3520
3426
|
// Keep a record of all the values we've reset
|
|
3521
|
-
|
|
3427
|
+
const resetValues = {};
|
|
3522
3428
|
// Check the rotate value of all axes and reset to 0
|
|
3523
|
-
for (
|
|
3524
|
-
|
|
3525
|
-
|
|
3429
|
+
for (let i = 0; i < transformAxes.length; i++) {
|
|
3430
|
+
const axis = transformAxes[i];
|
|
3431
|
+
const key = "rotate" + axis;
|
|
3526
3432
|
// If this rotation doesn't exist as a motion value, then we don't
|
|
3527
3433
|
// need to reset it
|
|
3528
3434
|
if (!visualElement.getStaticValue(key)) {
|
|
@@ -3540,18 +3446,17 @@
|
|
|
3540
3446
|
// set to 0.
|
|
3541
3447
|
visualElement === null || visualElement === void 0 ? void 0 : visualElement.syncRender();
|
|
3542
3448
|
// Put back all the values we reset
|
|
3543
|
-
for (
|
|
3449
|
+
for (const key in resetValues) {
|
|
3544
3450
|
visualElement.setStaticValue(key, resetValues[key]);
|
|
3545
3451
|
}
|
|
3546
3452
|
// Schedule a render for the next frame. This ensures we won't visually
|
|
3547
3453
|
// see the element with the reset rotate value applied.
|
|
3548
3454
|
visualElement.scheduleRender();
|
|
3549
|
-
}
|
|
3550
|
-
|
|
3455
|
+
}
|
|
3456
|
+
getProjectionStyles(styleProp = {}) {
|
|
3551
3457
|
var _a, _b, _c, _d, _e, _f;
|
|
3552
|
-
if (styleProp === void 0) { styleProp = {}; }
|
|
3553
3458
|
// TODO: Return lifecycle-persistent object
|
|
3554
|
-
|
|
3459
|
+
const styles = {};
|
|
3555
3460
|
if (!this.instance || this.isSVG)
|
|
3556
3461
|
return styles;
|
|
3557
3462
|
if (!this.isVisible) {
|
|
@@ -3560,7 +3465,7 @@
|
|
|
3560
3465
|
else {
|
|
3561
3466
|
styles.visibility = "";
|
|
3562
3467
|
}
|
|
3563
|
-
|
|
3468
|
+
const transformTemplate = (_a = this.options.visualElement) === null || _a === void 0 ? void 0 : _a.getProps().transformTemplate;
|
|
3564
3469
|
if (this.needsReset) {
|
|
3565
3470
|
this.needsReset = false;
|
|
3566
3471
|
styles.opacity = "";
|
|
@@ -3571,9 +3476,9 @@
|
|
|
3571
3476
|
: "none";
|
|
3572
3477
|
return styles;
|
|
3573
3478
|
}
|
|
3574
|
-
|
|
3479
|
+
const lead = this.getLead();
|
|
3575
3480
|
if (!this.projectionDelta || !this.layout || !lead.target) {
|
|
3576
|
-
|
|
3481
|
+
const emptyStyles = {};
|
|
3577
3482
|
if (this.options.layoutId) {
|
|
3578
3483
|
emptyStyles.opacity = (_b = this.latestValues.opacity) !== null && _b !== void 0 ? _b : 1;
|
|
3579
3484
|
emptyStyles.pointerEvents =
|
|
@@ -3587,14 +3492,14 @@
|
|
|
3587
3492
|
}
|
|
3588
3493
|
return emptyStyles;
|
|
3589
3494
|
}
|
|
3590
|
-
|
|
3495
|
+
const valuesToRender = lead.animationValues || lead.latestValues;
|
|
3591
3496
|
this.applyTransformsToTarget();
|
|
3592
3497
|
styles.transform = buildProjectionTransform(this.projectionDeltaWithTransform, this.treeScale, valuesToRender);
|
|
3593
3498
|
if (transformTemplate) {
|
|
3594
3499
|
styles.transform = transformTemplate(valuesToRender, styles.transform);
|
|
3595
3500
|
}
|
|
3596
|
-
|
|
3597
|
-
styles.transformOrigin =
|
|
3501
|
+
const { x, y } = this.projectionDelta;
|
|
3502
|
+
styles.transformOrigin = `${x.origin * 100}% ${y.origin * 100}% 0`;
|
|
3598
3503
|
if (lead.animationValues) {
|
|
3599
3504
|
/**
|
|
3600
3505
|
* If the lead component is animating, assign this either the entering/leaving
|
|
@@ -3620,14 +3525,14 @@
|
|
|
3620
3525
|
/**
|
|
3621
3526
|
* Apply scale correction
|
|
3622
3527
|
*/
|
|
3623
|
-
for (
|
|
3528
|
+
for (const key in scaleCorrectors) {
|
|
3624
3529
|
if (valuesToRender[key] === undefined)
|
|
3625
3530
|
continue;
|
|
3626
|
-
|
|
3627
|
-
|
|
3531
|
+
const { correct, applyTo } = scaleCorrectors[key];
|
|
3532
|
+
const corrected = correct(valuesToRender[key], lead);
|
|
3628
3533
|
if (applyTo) {
|
|
3629
|
-
|
|
3630
|
-
for (
|
|
3534
|
+
const num = applyTo.length;
|
|
3535
|
+
for (let i = 0; i < num; i++) {
|
|
3631
3536
|
styles[applyTo[i]] = corrected;
|
|
3632
3537
|
}
|
|
3633
3538
|
}
|
|
@@ -3647,62 +3552,61 @@
|
|
|
3647
3552
|
: "none";
|
|
3648
3553
|
}
|
|
3649
3554
|
return styles;
|
|
3650
|
-
}
|
|
3651
|
-
|
|
3555
|
+
}
|
|
3556
|
+
clearSnapshot() {
|
|
3652
3557
|
this.resumeFrom = this.snapshot = undefined;
|
|
3653
|
-
}
|
|
3558
|
+
}
|
|
3654
3559
|
// Only run on root
|
|
3655
|
-
|
|
3656
|
-
this.root.nodes.forEach(
|
|
3560
|
+
resetTree() {
|
|
3561
|
+
this.root.nodes.forEach((node) => { var _a; return (_a = node.currentAnimation) === null || _a === void 0 ? void 0 : _a.stop(); });
|
|
3657
3562
|
this.root.nodes.forEach(clearMeasurements);
|
|
3658
3563
|
this.root.sharedNodes.clear();
|
|
3659
|
-
}
|
|
3660
|
-
|
|
3661
|
-
}());
|
|
3564
|
+
}
|
|
3565
|
+
};
|
|
3662
3566
|
}
|
|
3663
3567
|
function updateLayout(node) {
|
|
3664
3568
|
node.updateLayout();
|
|
3665
3569
|
}
|
|
3666
3570
|
function notifyLayoutUpdate(node) {
|
|
3667
3571
|
var _a, _b, _c, _d;
|
|
3668
|
-
|
|
3572
|
+
const snapshot = (_b = (_a = node.resumeFrom) === null || _a === void 0 ? void 0 : _a.snapshot) !== null && _b !== void 0 ? _b : node.snapshot;
|
|
3669
3573
|
if (node.isLead() &&
|
|
3670
3574
|
node.layout &&
|
|
3671
3575
|
snapshot &&
|
|
3672
3576
|
node.hasListeners("didUpdate")) {
|
|
3673
|
-
|
|
3577
|
+
const { actual: layout, measured: measuredLayout } = node.layout;
|
|
3674
3578
|
// TODO Maybe we want to also resize the layout snapshot so we don't trigger
|
|
3675
3579
|
// animations for instance if layout="size" and an element has only changed position
|
|
3676
3580
|
if (node.options.animationType === "size") {
|
|
3677
|
-
eachAxis(
|
|
3678
|
-
|
|
3581
|
+
eachAxis((axis) => {
|
|
3582
|
+
const axisSnapshot = snapshot.isShared
|
|
3679
3583
|
? snapshot.measured[axis]
|
|
3680
3584
|
: snapshot.layout[axis];
|
|
3681
|
-
|
|
3682
|
-
axisSnapshot.min =
|
|
3585
|
+
const length = calcLength(axisSnapshot);
|
|
3586
|
+
axisSnapshot.min = layout[axis].min;
|
|
3683
3587
|
axisSnapshot.max = axisSnapshot.min + length;
|
|
3684
3588
|
});
|
|
3685
3589
|
}
|
|
3686
3590
|
else if (node.options.animationType === "position") {
|
|
3687
|
-
eachAxis(
|
|
3688
|
-
|
|
3591
|
+
eachAxis((axis) => {
|
|
3592
|
+
const axisSnapshot = snapshot.isShared
|
|
3689
3593
|
? snapshot.measured[axis]
|
|
3690
3594
|
: snapshot.layout[axis];
|
|
3691
|
-
|
|
3595
|
+
const length = calcLength(layout[axis]);
|
|
3692
3596
|
axisSnapshot.max = axisSnapshot.min + length;
|
|
3693
3597
|
});
|
|
3694
3598
|
}
|
|
3695
|
-
|
|
3696
|
-
calcBoxDelta(layoutDelta,
|
|
3697
|
-
|
|
3599
|
+
const layoutDelta = createDelta();
|
|
3600
|
+
calcBoxDelta(layoutDelta, layout, snapshot.layout);
|
|
3601
|
+
const visualDelta = createDelta();
|
|
3698
3602
|
if (snapshot.isShared) {
|
|
3699
3603
|
calcBoxDelta(visualDelta, node.applyTransform(measuredLayout, true), snapshot.measured);
|
|
3700
3604
|
}
|
|
3701
3605
|
else {
|
|
3702
|
-
calcBoxDelta(visualDelta,
|
|
3606
|
+
calcBoxDelta(visualDelta, layout, snapshot.layout);
|
|
3703
3607
|
}
|
|
3704
|
-
|
|
3705
|
-
|
|
3608
|
+
const hasLayoutChanged = !isDeltaZero(layoutDelta);
|
|
3609
|
+
let hasRelativeTargetChanged = false;
|
|
3706
3610
|
if (!node.resumeFrom) {
|
|
3707
3611
|
node.relativeParent = node.getClosestProjectingParent();
|
|
3708
3612
|
/**
|
|
@@ -3710,12 +3614,12 @@
|
|
|
3710
3614
|
* the relative snapshot is not relavent
|
|
3711
3615
|
*/
|
|
3712
3616
|
if (node.relativeParent && !node.relativeParent.resumeFrom) {
|
|
3713
|
-
|
|
3617
|
+
const { snapshot: parentSnapshot, layout: parentLayout } = node.relativeParent;
|
|
3714
3618
|
if (parentSnapshot && parentLayout) {
|
|
3715
|
-
|
|
3619
|
+
const relativeSnapshot = createBox();
|
|
3716
3620
|
calcRelativePosition(relativeSnapshot, snapshot.layout, parentSnapshot.layout);
|
|
3717
|
-
|
|
3718
|
-
calcRelativePosition(relativeLayout,
|
|
3621
|
+
const relativeLayout = createBox();
|
|
3622
|
+
calcRelativePosition(relativeLayout, layout, parentLayout.actual);
|
|
3719
3623
|
if (!boxEquals(relativeSnapshot, relativeLayout)) {
|
|
3720
3624
|
hasRelativeTargetChanged = true;
|
|
3721
3625
|
}
|
|
@@ -3723,12 +3627,12 @@
|
|
|
3723
3627
|
}
|
|
3724
3628
|
}
|
|
3725
3629
|
node.notifyListeners("didUpdate", {
|
|
3726
|
-
layout
|
|
3727
|
-
snapshot
|
|
3630
|
+
layout,
|
|
3631
|
+
snapshot,
|
|
3728
3632
|
delta: visualDelta,
|
|
3729
|
-
layoutDelta
|
|
3730
|
-
hasLayoutChanged
|
|
3731
|
-
hasRelativeTargetChanged
|
|
3633
|
+
layoutDelta,
|
|
3634
|
+
hasLayoutChanged,
|
|
3635
|
+
hasRelativeTargetChanged,
|
|
3732
3636
|
});
|
|
3733
3637
|
}
|
|
3734
3638
|
else if (node.isLead()) {
|
|
@@ -3748,7 +3652,7 @@
|
|
|
3748
3652
|
node.clearMeasurements();
|
|
3749
3653
|
}
|
|
3750
3654
|
function resetTransformStyle(node) {
|
|
3751
|
-
|
|
3655
|
+
const { visualElement } = node.options;
|
|
3752
3656
|
if (visualElement === null || visualElement === void 0 ? void 0 : visualElement.getProps().onBeforeLayoutMeasure) {
|
|
3753
3657
|
visualElement.notifyBeforeLayoutMeasure();
|
|
3754
3658
|
}
|
|
@@ -3787,7 +3691,7 @@
|
|
|
3787
3691
|
function hasOpacityCrossfade(node) {
|
|
3788
3692
|
return (node.animationValues && node.animationValues.opacityExit !== undefined);
|
|
3789
3693
|
}
|
|
3790
|
-
|
|
3694
|
+
const defaultLayoutTransition = {
|
|
3791
3695
|
duration: 0.45,
|
|
3792
3696
|
ease: [0.4, 0, 0.1, 1],
|
|
3793
3697
|
};
|
|
@@ -3796,15 +3700,15 @@
|
|
|
3796
3700
|
* Rather than searching the DOM from document we can search the
|
|
3797
3701
|
* path for the deepest mounted ancestor and search from there
|
|
3798
3702
|
*/
|
|
3799
|
-
|
|
3800
|
-
for (
|
|
3703
|
+
let searchNode = node.root;
|
|
3704
|
+
for (let i = node.path.length - 1; i >= 0; i--) {
|
|
3801
3705
|
if (Boolean(node.path[i].instance)) {
|
|
3802
3706
|
searchNode = node.path[i];
|
|
3803
3707
|
break;
|
|
3804
3708
|
}
|
|
3805
3709
|
}
|
|
3806
|
-
|
|
3807
|
-
|
|
3710
|
+
const searchElement = searchNode && searchNode !== node.root ? searchNode.instance : document;
|
|
3711
|
+
const element = searchElement.querySelector(`[data-projection-id="${id}"]`);
|
|
3808
3712
|
if (element)
|
|
3809
3713
|
node.mount(element, true);
|
|
3810
3714
|
}
|
|
@@ -3817,59 +3721,54 @@
|
|
|
3817
3721
|
roundAxis(box.y);
|
|
3818
3722
|
}
|
|
3819
3723
|
|
|
3820
|
-
function addDomEvent(target, eventName, handler, options) {
|
|
3821
|
-
if (options === void 0) { options = { passive: true }; }
|
|
3724
|
+
function addDomEvent(target, eventName, handler, options = { passive: true }) {
|
|
3822
3725
|
target.addEventListener(eventName, handler, options);
|
|
3823
|
-
return
|
|
3726
|
+
return () => target.removeEventListener(eventName, handler);
|
|
3824
3727
|
}
|
|
3825
3728
|
|
|
3826
|
-
|
|
3827
|
-
attachResizeListener:
|
|
3828
|
-
measureScroll:
|
|
3729
|
+
const DocumentProjectionNode = createProjectionNode({
|
|
3730
|
+
attachResizeListener: (ref, notify) => addDomEvent(ref, "resize", notify),
|
|
3731
|
+
measureScroll: () => ({
|
|
3829
3732
|
x: document.documentElement.scrollLeft || document.body.scrollLeft,
|
|
3830
3733
|
y: document.documentElement.scrollTop || document.body.scrollTop,
|
|
3831
|
-
})
|
|
3832
|
-
checkIsScrollRoot:
|
|
3734
|
+
}),
|
|
3735
|
+
checkIsScrollRoot: () => true,
|
|
3833
3736
|
});
|
|
3834
3737
|
|
|
3835
|
-
|
|
3738
|
+
const rootProjectionNode = {
|
|
3836
3739
|
current: undefined,
|
|
3837
3740
|
};
|
|
3838
|
-
|
|
3839
|
-
measureScroll:
|
|
3741
|
+
const HTMLProjectionNode = createProjectionNode({
|
|
3742
|
+
measureScroll: (instance) => ({
|
|
3840
3743
|
x: instance.scrollLeft,
|
|
3841
3744
|
y: instance.scrollTop,
|
|
3842
|
-
})
|
|
3843
|
-
defaultParent:
|
|
3745
|
+
}),
|
|
3746
|
+
defaultParent: () => {
|
|
3844
3747
|
if (!rootProjectionNode.current) {
|
|
3845
|
-
|
|
3748
|
+
const documentNode = new DocumentProjectionNode(0, {});
|
|
3846
3749
|
documentNode.mount(window);
|
|
3847
3750
|
documentNode.setOptions({ layoutScroll: true });
|
|
3848
3751
|
rootProjectionNode.current = documentNode;
|
|
3849
3752
|
}
|
|
3850
3753
|
return rootProjectionNode.current;
|
|
3851
3754
|
},
|
|
3852
|
-
resetTransform:
|
|
3755
|
+
resetTransform: (instance, value) => {
|
|
3853
3756
|
instance.style.transform = value !== null && value !== void 0 ? value : "none";
|
|
3854
3757
|
},
|
|
3855
|
-
checkIsScrollRoot:
|
|
3856
|
-
return Boolean(window.getComputedStyle(instance).position === "fixed");
|
|
3857
|
-
},
|
|
3758
|
+
checkIsScrollRoot: (instance) => Boolean(window.getComputedStyle(instance).position === "fixed"),
|
|
3858
3759
|
});
|
|
3859
3760
|
|
|
3860
|
-
|
|
3861
|
-
return !node.isLayoutDirty && node.willUpdate(false);
|
|
3862
|
-
};
|
|
3761
|
+
const notify = (node) => !node.isLayoutDirty && node.willUpdate(false);
|
|
3863
3762
|
function nodeGroup() {
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3763
|
+
const nodes = new Set();
|
|
3764
|
+
const subscriptions = new WeakMap();
|
|
3765
|
+
const dirtyAll = () => nodes.forEach(notify);
|
|
3867
3766
|
return {
|
|
3868
|
-
add:
|
|
3767
|
+
add: (node) => {
|
|
3869
3768
|
nodes.add(node);
|
|
3870
3769
|
subscriptions.set(node, node.addEventListener("willUpdate", dirtyAll));
|
|
3871
3770
|
},
|
|
3872
|
-
remove:
|
|
3771
|
+
remove: (node) => {
|
|
3873
3772
|
var _a;
|
|
3874
3773
|
nodes.delete(node);
|
|
3875
3774
|
(_a = subscriptions.get(node)) === null || _a === void 0 ? void 0 : _a();
|
|
@@ -3880,7 +3779,7 @@
|
|
|
3880
3779
|
};
|
|
3881
3780
|
}
|
|
3882
3781
|
|
|
3883
|
-
|
|
3782
|
+
const translateAlias = {
|
|
3884
3783
|
x: "translateX",
|
|
3885
3784
|
y: "translateY",
|
|
3886
3785
|
z: "translateZ",
|
|
@@ -3892,30 +3791,26 @@
|
|
|
3892
3791
|
* This outputs with a default order of transforms/scales/rotations, this can be customised by
|
|
3893
3792
|
* providing a transformTemplate function.
|
|
3894
3793
|
*/
|
|
3895
|
-
function buildTransform(
|
|
3896
|
-
var transform = _a.transform, transformKeys = _a.transformKeys;
|
|
3897
|
-
var _c = _b.enableHardwareAcceleration, enableHardwareAcceleration = _c === void 0 ? true : _c, _d = _b.allowTransformNone, allowTransformNone = _d === void 0 ? true : _d;
|
|
3794
|
+
function buildTransform({ transform, transformKeys }, { enableHardwareAcceleration = true, allowTransformNone = true, }, transformIsDefault, transformTemplate) {
|
|
3898
3795
|
// The transform string we're going to build into.
|
|
3899
|
-
|
|
3796
|
+
let transformString = "";
|
|
3900
3797
|
// Transform keys into their default order - this will determine the output order.
|
|
3901
3798
|
transformKeys.sort(sortTransformProps);
|
|
3902
3799
|
// Track whether the defined transform has a defined z so we don't add a
|
|
3903
3800
|
// second to enable hardware acceleration
|
|
3904
|
-
|
|
3801
|
+
let transformHasZ = false;
|
|
3905
3802
|
// Loop over each transform and build them into transformString
|
|
3906
|
-
|
|
3907
|
-
for (
|
|
3908
|
-
|
|
3909
|
-
transformString +=
|
|
3803
|
+
const numTransformKeys = transformKeys.length;
|
|
3804
|
+
for (let i = 0; i < numTransformKeys; i++) {
|
|
3805
|
+
const key = transformKeys[i];
|
|
3806
|
+
transformString += `${translateAlias[key] || key}(${transform[key]}) `;
|
|
3910
3807
|
if (key === "z")
|
|
3911
3808
|
transformHasZ = true;
|
|
3912
3809
|
}
|
|
3913
3810
|
if (!transformHasZ && enableHardwareAcceleration) {
|
|
3914
3811
|
transformString += "translateZ(0)";
|
|
3915
3812
|
}
|
|
3916
|
-
|
|
3917
|
-
transformString = transformString.trim();
|
|
3918
|
-
}
|
|
3813
|
+
transformString = transformString.trim();
|
|
3919
3814
|
// If we have a custom `transform` template, pass our transform values and
|
|
3920
3815
|
// generated transformString to that before returning
|
|
3921
3816
|
if (transformTemplate) {
|
|
@@ -3930,9 +3825,8 @@
|
|
|
3930
3825
|
* Build a transformOrigin style. Uses the same defaults as the browser for
|
|
3931
3826
|
* undefined origins.
|
|
3932
3827
|
*/
|
|
3933
|
-
function buildTransformOrigin(
|
|
3934
|
-
|
|
3935
|
-
return "".concat(originX, " ").concat(originY, " ").concat(originZ);
|
|
3828
|
+
function buildTransformOrigin({ originX = "50%", originY = "50%", originZ = 0, }) {
|
|
3829
|
+
return `${originX} ${originY} ${originZ}`;
|
|
3936
3830
|
}
|
|
3937
3831
|
|
|
3938
3832
|
function pixelsToPercent(pixels, axis) {
|
|
@@ -3947,8 +3841,8 @@
|
|
|
3947
3841
|
* borderRadius in both states. If we animate between the two in pixels that will trigger
|
|
3948
3842
|
* a paint each time. If we animate between the two in percentage we'll avoid a paint.
|
|
3949
3843
|
*/
|
|
3950
|
-
|
|
3951
|
-
correct:
|
|
3844
|
+
const correctBorderRadius = {
|
|
3845
|
+
correct: (latest, node) => {
|
|
3952
3846
|
if (!node.target)
|
|
3953
3847
|
return latest;
|
|
3954
3848
|
/**
|
|
@@ -3967,9 +3861,9 @@
|
|
|
3967
3861
|
* If latest is a number, it's a pixel value. We use the current viewportBox to calculate that
|
|
3968
3862
|
* pixel value as a percentage of each axis
|
|
3969
3863
|
*/
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
return
|
|
3864
|
+
const x = pixelsToPercent(latest, node.target.x);
|
|
3865
|
+
const y = pixelsToPercent(latest, node.target.y);
|
|
3866
|
+
return `${x}% ${y}%`;
|
|
3973
3867
|
},
|
|
3974
3868
|
};
|
|
3975
3869
|
|
|
@@ -3985,24 +3879,23 @@
|
|
|
3985
3879
|
*
|
|
3986
3880
|
* @param current
|
|
3987
3881
|
*/
|
|
3988
|
-
|
|
3882
|
+
const cssVariableRegex = /var\((--[a-zA-Z0-9-_]+),? ?([a-zA-Z0-9 ()%#.,-]+)?\)/;
|
|
3989
3883
|
function parseCSSVariable(current) {
|
|
3990
|
-
|
|
3884
|
+
const match = cssVariableRegex.exec(current);
|
|
3991
3885
|
if (!match)
|
|
3992
3886
|
return [,];
|
|
3993
|
-
|
|
3887
|
+
const [, token, fallback] = match;
|
|
3994
3888
|
return [token, fallback];
|
|
3995
3889
|
}
|
|
3996
|
-
|
|
3997
|
-
function getVariableValue(current, element, depth) {
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
var _a = __read(parseCSSVariable(current), 2), token = _a[0], fallback = _a[1];
|
|
3890
|
+
const maxDepth = 4;
|
|
3891
|
+
function getVariableValue(current, element, depth = 1) {
|
|
3892
|
+
invariant(depth <= maxDepth, `Max CSS variable fallback depth detected in property "${current}". This may indicate a circular fallback dependency.`);
|
|
3893
|
+
const [token, fallback] = parseCSSVariable(current);
|
|
4001
3894
|
// No CSS variable detected
|
|
4002
3895
|
if (!token)
|
|
4003
3896
|
return;
|
|
4004
3897
|
// Attempt to read this CSS variable off the element
|
|
4005
|
-
|
|
3898
|
+
const resolved = window.getComputedStyle(element).getPropertyValue(token);
|
|
4006
3899
|
if (resolved) {
|
|
4007
3900
|
return resolved.trim();
|
|
4008
3901
|
}
|
|
@@ -4022,30 +3915,30 @@
|
|
|
4022
3915
|
function resolveCSSVariables(visualElement, _a, transitionEnd) {
|
|
4023
3916
|
var _b;
|
|
4024
3917
|
var target = __rest(_a, []);
|
|
4025
|
-
|
|
3918
|
+
const element = visualElement.getInstance();
|
|
4026
3919
|
if (!(element instanceof Element))
|
|
4027
|
-
return { target
|
|
3920
|
+
return { target, transitionEnd };
|
|
4028
3921
|
// If `transitionEnd` isn't `undefined`, clone it. We could clone `target` and `transitionEnd`
|
|
4029
3922
|
// only if they change but I think this reads clearer and this isn't a performance-critical path.
|
|
4030
3923
|
if (transitionEnd) {
|
|
4031
|
-
transitionEnd =
|
|
3924
|
+
transitionEnd = Object.assign({}, transitionEnd);
|
|
4032
3925
|
}
|
|
4033
3926
|
// Go through existing `MotionValue`s and ensure any existing CSS variables are resolved
|
|
4034
|
-
visualElement.forEachValue(
|
|
4035
|
-
|
|
3927
|
+
visualElement.forEachValue((value) => {
|
|
3928
|
+
const current = value.get();
|
|
4036
3929
|
if (!isCSSVariable$1(current))
|
|
4037
3930
|
return;
|
|
4038
|
-
|
|
3931
|
+
const resolved = getVariableValue(current, element);
|
|
4039
3932
|
if (resolved)
|
|
4040
3933
|
value.set(resolved);
|
|
4041
3934
|
});
|
|
4042
3935
|
// Cycle through every target property and resolve CSS variables. Currently
|
|
4043
3936
|
// we only read single-var properties like `var(--foo)`, not `calc(var(--foo) + 20px)`
|
|
4044
|
-
for (
|
|
4045
|
-
|
|
3937
|
+
for (const key in target) {
|
|
3938
|
+
const current = target[key];
|
|
4046
3939
|
if (!isCSSVariable$1(current))
|
|
4047
3940
|
continue;
|
|
4048
|
-
|
|
3941
|
+
const resolved = getVariableValue(current, element);
|
|
4049
3942
|
if (!resolved)
|
|
4050
3943
|
continue;
|
|
4051
3944
|
// Clone target if it hasn't already been
|
|
@@ -4056,34 +3949,33 @@
|
|
|
4056
3949
|
if (transitionEnd)
|
|
4057
3950
|
(_b = transitionEnd[key]) !== null && _b !== void 0 ? _b : (transitionEnd[key] = current);
|
|
4058
3951
|
}
|
|
4059
|
-
return { target
|
|
3952
|
+
return { target, transitionEnd };
|
|
4060
3953
|
}
|
|
4061
3954
|
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
correct:
|
|
4065
|
-
|
|
4066
|
-
var original = latest;
|
|
3955
|
+
const varToken = "_$css";
|
|
3956
|
+
const correctBoxShadow = {
|
|
3957
|
+
correct: (latest, { treeScale, projectionDelta }) => {
|
|
3958
|
+
const original = latest;
|
|
4067
3959
|
/**
|
|
4068
3960
|
* We need to first strip and store CSS variables from the string.
|
|
4069
3961
|
*/
|
|
4070
|
-
|
|
4071
|
-
|
|
3962
|
+
const containsCSSVariables = latest.includes("var(");
|
|
3963
|
+
const cssVariables = [];
|
|
4072
3964
|
if (containsCSSVariables) {
|
|
4073
|
-
latest = latest.replace(cssVariableRegex,
|
|
3965
|
+
latest = latest.replace(cssVariableRegex, (match) => {
|
|
4074
3966
|
cssVariables.push(match);
|
|
4075
3967
|
return varToken;
|
|
4076
3968
|
});
|
|
4077
3969
|
}
|
|
4078
|
-
|
|
3970
|
+
const shadow = complex.parse(latest);
|
|
4079
3971
|
// TODO: Doesn't support multiple shadows
|
|
4080
3972
|
if (shadow.length > 5)
|
|
4081
3973
|
return original;
|
|
4082
|
-
|
|
4083
|
-
|
|
3974
|
+
const template = complex.createTransformer(latest);
|
|
3975
|
+
const offset = typeof shadow[0] !== "number" ? 1 : 0;
|
|
4084
3976
|
// Calculate the overall context scale
|
|
4085
|
-
|
|
4086
|
-
|
|
3977
|
+
const xScale = projectionDelta.x.scale * treeScale.x;
|
|
3978
|
+
const yScale = projectionDelta.y.scale * treeScale.y;
|
|
4087
3979
|
shadow[0 + offset] /= xScale;
|
|
4088
3980
|
shadow[1 + offset] /= yScale;
|
|
4089
3981
|
/**
|
|
@@ -4092,19 +3984,19 @@
|
|
|
4092
3984
|
* We could potentially improve the outcome of this by incorporating the ratio between
|
|
4093
3985
|
* the two scales.
|
|
4094
3986
|
*/
|
|
4095
|
-
|
|
3987
|
+
const averageScale = mix(xScale, yScale, 0.5);
|
|
4096
3988
|
// Blur
|
|
4097
3989
|
if (typeof shadow[2 + offset] === "number")
|
|
4098
3990
|
shadow[2 + offset] /= averageScale;
|
|
4099
3991
|
// Spread
|
|
4100
3992
|
if (typeof shadow[3 + offset] === "number")
|
|
4101
3993
|
shadow[3 + offset] /= averageScale;
|
|
4102
|
-
|
|
3994
|
+
let output = template(shadow);
|
|
4103
3995
|
if (containsCSSVariables) {
|
|
4104
|
-
|
|
4105
|
-
output = output.replace(varToken,
|
|
4106
|
-
|
|
4107
|
-
|
|
3996
|
+
let i = 0;
|
|
3997
|
+
output = output.replace(varToken, () => {
|
|
3998
|
+
const cssVariable = cssVariables[i];
|
|
3999
|
+
i++;
|
|
4108
4000
|
return cssVariable;
|
|
4109
4001
|
});
|
|
4110
4002
|
}
|
|
@@ -4112,48 +4004,50 @@
|
|
|
4112
4004
|
},
|
|
4113
4005
|
};
|
|
4114
4006
|
|
|
4007
|
+
function isWillChangeMotionValue(value) {
|
|
4008
|
+
return Boolean(isMotionValue(value) && value.add);
|
|
4009
|
+
}
|
|
4010
|
+
|
|
4115
4011
|
/**
|
|
4116
4012
|
* Check if value is a numerical string, ie a string that is purely a number eg "100" or "-100.1"
|
|
4117
4013
|
*/
|
|
4118
|
-
|
|
4014
|
+
const isNumericalString = (v) => /^\-?\d*\.?\d+$/.test(v);
|
|
4119
4015
|
|
|
4120
4016
|
/**
|
|
4121
4017
|
* Check if the value is a zero value string like "0px" or "0%"
|
|
4122
4018
|
*/
|
|
4123
|
-
|
|
4019
|
+
const isZeroValueString = (v) => /^0[^.\s]+$/.test(v);
|
|
4124
4020
|
|
|
4125
4021
|
/**
|
|
4126
4022
|
* Tests a provided value against a ValueType
|
|
4127
4023
|
*/
|
|
4128
|
-
|
|
4024
|
+
const testValueType = (v) => (type) => type.test(v);
|
|
4129
4025
|
|
|
4130
4026
|
/**
|
|
4131
4027
|
* ValueType for "auto"
|
|
4132
4028
|
*/
|
|
4133
|
-
|
|
4134
|
-
test:
|
|
4135
|
-
parse:
|
|
4029
|
+
const auto = {
|
|
4030
|
+
test: (v) => v === "auto",
|
|
4031
|
+
parse: (v) => v,
|
|
4136
4032
|
};
|
|
4137
4033
|
|
|
4138
4034
|
/**
|
|
4139
4035
|
* A list of value types commonly used for dimensions
|
|
4140
4036
|
*/
|
|
4141
|
-
|
|
4037
|
+
const dimensionValueTypes = [number, px, percent, degrees, vw, vh, auto];
|
|
4142
4038
|
/**
|
|
4143
4039
|
* Tests a dimensional value against the list of dimension ValueTypes
|
|
4144
4040
|
*/
|
|
4145
|
-
|
|
4146
|
-
return dimensionValueTypes.find(testValueType(v));
|
|
4147
|
-
};
|
|
4041
|
+
const findDimensionValueType = (v) => dimensionValueTypes.find(testValueType(v));
|
|
4148
4042
|
|
|
4149
4043
|
/**
|
|
4150
4044
|
* A list of all ValueTypes
|
|
4151
4045
|
*/
|
|
4152
|
-
|
|
4046
|
+
const valueTypes = [...dimensionValueTypes, color, complex];
|
|
4153
4047
|
/**
|
|
4154
4048
|
* Tests a value against the list of ValueTypes
|
|
4155
4049
|
*/
|
|
4156
|
-
|
|
4050
|
+
const findValueType = (v) => valueTypes.find(testValueType(v));
|
|
4157
4051
|
|
|
4158
4052
|
/**
|
|
4159
4053
|
* Decides if the supplied variable is an array of variant labels
|
|
@@ -4185,14 +4079,14 @@
|
|
|
4185
4079
|
function checkTargetForNewValues(visualElement, target, origin) {
|
|
4186
4080
|
var _a, _b, _c;
|
|
4187
4081
|
var _d;
|
|
4188
|
-
|
|
4189
|
-
|
|
4082
|
+
const newValueKeys = Object.keys(target).filter((key) => !visualElement.hasValue(key));
|
|
4083
|
+
const numNewValues = newValueKeys.length;
|
|
4190
4084
|
if (!numNewValues)
|
|
4191
4085
|
return;
|
|
4192
|
-
for (
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4086
|
+
for (let i = 0; i < numNewValues; i++) {
|
|
4087
|
+
const key = newValueKeys[i];
|
|
4088
|
+
const targetValue = target[key];
|
|
4089
|
+
let value = null;
|
|
4196
4090
|
/**
|
|
4197
4091
|
* If the target is a series of keyframes, we can use the first value
|
|
4198
4092
|
* in the array. If this first value is null, we'll still need to read from the DOM.
|
|
@@ -4230,13 +4124,13 @@
|
|
|
4230
4124
|
function getOriginFromTransition(key, transition) {
|
|
4231
4125
|
if (!transition)
|
|
4232
4126
|
return;
|
|
4233
|
-
|
|
4127
|
+
const valueTransition = transition[key] || transition["default"] || transition;
|
|
4234
4128
|
return valueTransition.from;
|
|
4235
4129
|
}
|
|
4236
4130
|
function getOrigin(target, transition, visualElement) {
|
|
4237
4131
|
var _a, _b;
|
|
4238
|
-
|
|
4239
|
-
for (
|
|
4132
|
+
const origin = {};
|
|
4133
|
+
for (const key in target) {
|
|
4240
4134
|
origin[key] =
|
|
4241
4135
|
(_a = getOriginFromTransition(key, transition)) !== null && _a !== void 0 ? _a : (_b = visualElement.getValue(key)) === null || _b === void 0 ? void 0 : _b.get();
|
|
4242
4136
|
}
|
|
@@ -4254,7 +4148,7 @@
|
|
|
4254
4148
|
AnimationType["Exit"] = "exit";
|
|
4255
4149
|
})(AnimationType || (AnimationType = {}));
|
|
4256
4150
|
|
|
4257
|
-
|
|
4151
|
+
const variantPriorityOrder = [
|
|
4258
4152
|
AnimationType.Animate,
|
|
4259
4153
|
AnimationType.InView,
|
|
4260
4154
|
AnimationType.Focus,
|
|
@@ -4263,10 +4157,8 @@
|
|
|
4263
4157
|
AnimationType.Drag,
|
|
4264
4158
|
AnimationType.Exit,
|
|
4265
4159
|
];
|
|
4266
|
-
__spreadArray([], __read(variantPriorityOrder), false).reverse();
|
|
4267
|
-
variantPriorityOrder.length;
|
|
4268
4160
|
|
|
4269
|
-
|
|
4161
|
+
const names = [
|
|
4270
4162
|
"LayoutMeasure",
|
|
4271
4163
|
"BeforeLayoutMeasure",
|
|
4272
4164
|
"LayoutUpdate",
|
|
@@ -4281,15 +4173,15 @@
|
|
|
4281
4173
|
"Unmount",
|
|
4282
4174
|
];
|
|
4283
4175
|
function createLifecycles() {
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
clearAllListeners:
|
|
4288
|
-
updatePropListeners:
|
|
4289
|
-
names.forEach(
|
|
4176
|
+
const managers = names.map(() => new SubscriptionManager());
|
|
4177
|
+
const propSubscriptions = {};
|
|
4178
|
+
const lifecycles = {
|
|
4179
|
+
clearAllListeners: () => managers.forEach((manager) => manager.clear()),
|
|
4180
|
+
updatePropListeners: (props) => {
|
|
4181
|
+
names.forEach((name) => {
|
|
4290
4182
|
var _a;
|
|
4291
|
-
|
|
4292
|
-
|
|
4183
|
+
const on = "on" + name;
|
|
4184
|
+
const propListener = props[on];
|
|
4293
4185
|
// Unsubscribe existing subscription
|
|
4294
4186
|
(_a = propSubscriptions[name]) === null || _a === void 0 ? void 0 : _a.call(propSubscriptions);
|
|
4295
4187
|
// Add new subscription
|
|
@@ -4299,20 +4191,14 @@
|
|
|
4299
4191
|
});
|
|
4300
4192
|
},
|
|
4301
4193
|
};
|
|
4302
|
-
managers.forEach(
|
|
4303
|
-
lifecycles["on" + names[i]] =
|
|
4304
|
-
lifecycles["notify" + names[i]] =
|
|
4305
|
-
var args = [];
|
|
4306
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
4307
|
-
args[_i] = arguments[_i];
|
|
4308
|
-
}
|
|
4309
|
-
return manager.notify.apply(manager, __spreadArray([], __read(args), false));
|
|
4310
|
-
};
|
|
4194
|
+
managers.forEach((manager, i) => {
|
|
4195
|
+
lifecycles["on" + names[i]] = (handler) => manager.add(handler);
|
|
4196
|
+
lifecycles["notify" + names[i]] = (...args) => manager.notify(...args);
|
|
4311
4197
|
});
|
|
4312
4198
|
return lifecycles;
|
|
4313
4199
|
}
|
|
4314
4200
|
|
|
4315
|
-
|
|
4201
|
+
const warned = new Set();
|
|
4316
4202
|
function warnOnce(condition, message, element) {
|
|
4317
4203
|
if (condition || warned.has(message))
|
|
4318
4204
|
return;
|
|
@@ -4324,29 +4210,36 @@
|
|
|
4324
4210
|
|
|
4325
4211
|
function updateMotionValuesFromProps(element, next, prev) {
|
|
4326
4212
|
var _a;
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4213
|
+
const { willChange } = next;
|
|
4214
|
+
for (const key in next) {
|
|
4215
|
+
const nextValue = next[key];
|
|
4216
|
+
const prevValue = prev[key];
|
|
4330
4217
|
if (isMotionValue(nextValue)) {
|
|
4331
4218
|
/**
|
|
4332
4219
|
* If this is a motion value found in props or style, we want to add it
|
|
4333
4220
|
* to our visual element's motion value map.
|
|
4334
4221
|
*/
|
|
4335
4222
|
element.addValue(key, nextValue);
|
|
4223
|
+
if (isWillChangeMotionValue(willChange)) {
|
|
4224
|
+
willChange.add(key);
|
|
4225
|
+
}
|
|
4336
4226
|
/**
|
|
4337
4227
|
* Check the version of the incoming motion value with this version
|
|
4338
4228
|
* and warn against mismatches.
|
|
4339
4229
|
*/
|
|
4340
4230
|
{
|
|
4341
|
-
warnOnce(nextValue.version === "7.
|
|
4231
|
+
warnOnce(nextValue.version === "7.1.2", `Attempting to mix Framer Motion versions ${nextValue.version} with 7.1.2 may not work as expected.`);
|
|
4342
4232
|
}
|
|
4343
4233
|
}
|
|
4344
4234
|
else if (isMotionValue(prevValue)) {
|
|
4345
4235
|
/**
|
|
4346
|
-
* If we're swapping
|
|
4347
|
-
* from that
|
|
4236
|
+
* If we're swapping from a motion value to a static value,
|
|
4237
|
+
* create a new motion value from that
|
|
4348
4238
|
*/
|
|
4349
4239
|
element.addValue(key, motionValue(nextValue));
|
|
4240
|
+
if (isWillChangeMotionValue(willChange)) {
|
|
4241
|
+
willChange.remove(key);
|
|
4242
|
+
}
|
|
4350
4243
|
}
|
|
4351
4244
|
else if (prevValue !== nextValue) {
|
|
4352
4245
|
/**
|
|
@@ -4355,7 +4248,7 @@
|
|
|
4355
4248
|
* not handling the value with our animation state.
|
|
4356
4249
|
*/
|
|
4357
4250
|
if (element.hasValue(key)) {
|
|
4358
|
-
|
|
4251
|
+
const existingValue = element.getValue(key);
|
|
4359
4252
|
// TODO: Only update values that aren't being animated or even looked at
|
|
4360
4253
|
!existingValue.hasAnimated && existingValue.set(nextValue);
|
|
4361
4254
|
}
|
|
@@ -4365,403 +4258,397 @@
|
|
|
4365
4258
|
}
|
|
4366
4259
|
}
|
|
4367
4260
|
// Handle removed values
|
|
4368
|
-
for (
|
|
4261
|
+
for (const key in prev) {
|
|
4369
4262
|
if (next[key] === undefined)
|
|
4370
4263
|
element.removeValue(key);
|
|
4371
4264
|
}
|
|
4372
4265
|
return next;
|
|
4373
4266
|
}
|
|
4374
4267
|
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4268
|
+
const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatable, measureViewportBox, render: renderInstance, readValueFromInstance, removeValueFromRenderState, sortNodePosition, scrapeMotionValuesFromProps, }) => ({ parent, props, presenceId, blockInitialAnimation, visualState, shouldReduceMotion, }, options = {}) => {
|
|
4269
|
+
let isMounted = false;
|
|
4270
|
+
const { latestValues, renderState } = visualState;
|
|
4271
|
+
/**
|
|
4272
|
+
* The instance of the render-specific node that will be hydrated by the
|
|
4273
|
+
* exposed React ref. So for example, this visual element can host a
|
|
4274
|
+
* HTMLElement, plain object, or Three.js object. The functions provided
|
|
4275
|
+
* in VisualElementConfig allow us to interface with this instance.
|
|
4276
|
+
*/
|
|
4277
|
+
let instance;
|
|
4278
|
+
/**
|
|
4279
|
+
* Manages the subscriptions for a visual element's lifecycle, for instance
|
|
4280
|
+
* onRender
|
|
4281
|
+
*/
|
|
4282
|
+
const lifecycles = createLifecycles();
|
|
4283
|
+
/**
|
|
4284
|
+
* A map of all motion values attached to this visual element. Motion
|
|
4285
|
+
* values are source of truth for any given animated value. A motion
|
|
4286
|
+
* value might be provided externally by the component via props.
|
|
4287
|
+
*/
|
|
4288
|
+
const values = new Map();
|
|
4289
|
+
/**
|
|
4290
|
+
* A map of every subscription that binds the provided or generated
|
|
4291
|
+
* motion values onChange listeners to this visual element.
|
|
4292
|
+
*/
|
|
4293
|
+
const valueSubscriptions = new Map();
|
|
4294
|
+
/**
|
|
4295
|
+
* A reference to the previously-provided motion values as returned
|
|
4296
|
+
* from scrapeMotionValuesFromProps. We use the keys in here to determine
|
|
4297
|
+
* if any motion values need to be removed after props are updated.
|
|
4298
|
+
*/
|
|
4299
|
+
let prevMotionValues = {};
|
|
4300
|
+
/**
|
|
4301
|
+
* When values are removed from all animation props we need to search
|
|
4302
|
+
* for a fallback value to animate to. These values are tracked in baseTarget.
|
|
4303
|
+
*/
|
|
4304
|
+
const baseTarget = Object.assign({}, latestValues);
|
|
4305
|
+
// Internal methods ========================
|
|
4306
|
+
/**
|
|
4307
|
+
* On mount, this will be hydrated with a callback to disconnect
|
|
4308
|
+
* this visual element from its parent on unmount.
|
|
4309
|
+
*/
|
|
4310
|
+
let removeFromVariantTree;
|
|
4311
|
+
/**
|
|
4312
|
+
* Render the element with the latest styles outside of the React
|
|
4313
|
+
* render lifecycle
|
|
4314
|
+
*/
|
|
4315
|
+
function render() {
|
|
4316
|
+
if (!instance || !isMounted)
|
|
4317
|
+
return;
|
|
4318
|
+
triggerBuild();
|
|
4319
|
+
renderInstance(instance, renderState, props.style, element.projection);
|
|
4320
|
+
}
|
|
4321
|
+
function triggerBuild() {
|
|
4322
|
+
build(element, renderState, latestValues, options, props);
|
|
4323
|
+
}
|
|
4324
|
+
function update() {
|
|
4325
|
+
lifecycles.notifyUpdate(latestValues);
|
|
4326
|
+
}
|
|
4327
|
+
/**
|
|
4328
|
+
*
|
|
4329
|
+
*/
|
|
4330
|
+
function bindToMotionValue(key, value) {
|
|
4331
|
+
const removeOnChange = value.onChange((latestValue) => {
|
|
4332
|
+
latestValues[key] = latestValue;
|
|
4333
|
+
props.onUpdate && sync.update(update, false, true);
|
|
4334
|
+
});
|
|
4335
|
+
const removeOnRenderRequest = value.onRenderRequest(element.scheduleRender);
|
|
4336
|
+
valueSubscriptions.set(key, () => {
|
|
4337
|
+
removeOnChange();
|
|
4338
|
+
removeOnRenderRequest();
|
|
4339
|
+
});
|
|
4340
|
+
}
|
|
4341
|
+
/**
|
|
4342
|
+
* Any motion values that are provided to the element when created
|
|
4343
|
+
* aren't yet bound to the element, as this would technically be impure.
|
|
4344
|
+
* However, we iterate through the motion values and set them to the
|
|
4345
|
+
* initial values for this component.
|
|
4346
|
+
*
|
|
4347
|
+
* TODO: This is impure and we should look at changing this to run on mount.
|
|
4348
|
+
* Doing so will break some tests but this isn't neccessarily a breaking change,
|
|
4349
|
+
* more a reflection of the test.
|
|
4350
|
+
*/
|
|
4351
|
+
const _a = scrapeMotionValuesFromProps(props), { willChange } = _a, initialMotionValues = __rest(_a, ["willChange"]);
|
|
4352
|
+
for (const key in initialMotionValues) {
|
|
4353
|
+
const value = initialMotionValues[key];
|
|
4354
|
+
if (latestValues[key] !== undefined && isMotionValue(value)) {
|
|
4355
|
+
value.set(latestValues[key], false);
|
|
4356
|
+
if (isWillChangeMotionValue(willChange)) {
|
|
4357
|
+
willChange.add(key);
|
|
4358
|
+
}
|
|
4359
|
+
}
|
|
4360
|
+
}
|
|
4361
|
+
/**
|
|
4362
|
+
* Determine what role this visual element should take in the variant tree.
|
|
4363
|
+
*/
|
|
4364
|
+
const isControllingVariants = checkIfControllingVariants(props);
|
|
4365
|
+
const isVariantNode = checkIfVariantNode(props);
|
|
4366
|
+
const element = Object.assign(Object.assign({ treeType,
|
|
4382
4367
|
/**
|
|
4383
|
-
*
|
|
4384
|
-
*
|
|
4385
|
-
* HTMLElement, plain object, or Three.js object. The functions provided
|
|
4386
|
-
* in VisualElementConfig allow us to interface with this instance.
|
|
4368
|
+
* This is a mirror of the internal instance prop, which keeps
|
|
4369
|
+
* VisualElement type-compatible with React's RefObject.
|
|
4387
4370
|
*/
|
|
4388
|
-
|
|
4371
|
+
current: null,
|
|
4389
4372
|
/**
|
|
4390
|
-
*
|
|
4391
|
-
* onRender
|
|
4373
|
+
* The depth of this visual element within the visual element tree.
|
|
4392
4374
|
*/
|
|
4393
|
-
|
|
4375
|
+
depth: parent ? parent.depth + 1 : 0, parent, children: new Set(),
|
|
4394
4376
|
/**
|
|
4395
|
-
*
|
|
4396
|
-
* values are source of truth for any given animated value. A motion
|
|
4397
|
-
* value might be provided externally by the component via props.
|
|
4377
|
+
*
|
|
4398
4378
|
*/
|
|
4399
|
-
|
|
4379
|
+
presenceId,
|
|
4380
|
+
shouldReduceMotion,
|
|
4400
4381
|
/**
|
|
4401
|
-
*
|
|
4402
|
-
*
|
|
4382
|
+
* If this component is part of the variant tree, it should track
|
|
4383
|
+
* any children that are also part of the tree. This is essentially
|
|
4384
|
+
* a shadow tree to simplify logic around how to stagger over children.
|
|
4403
4385
|
*/
|
|
4404
|
-
|
|
4386
|
+
variantChildren: isVariantNode ? new Set() : undefined,
|
|
4405
4387
|
/**
|
|
4406
|
-
*
|
|
4407
|
-
*
|
|
4408
|
-
*
|
|
4388
|
+
* Whether this instance is visible. This can be changed imperatively
|
|
4389
|
+
* by the projection tree, is analogous to CSS's visibility in that
|
|
4390
|
+
* hidden elements should take up layout, and needs enacting by the configured
|
|
4391
|
+
* render function.
|
|
4409
4392
|
*/
|
|
4410
|
-
|
|
4393
|
+
isVisible: undefined,
|
|
4411
4394
|
/**
|
|
4412
|
-
*
|
|
4413
|
-
*
|
|
4395
|
+
* Normally, if a component is controlled by a parent's variants, it can
|
|
4396
|
+
* rely on that ancestor to trigger animations further down the tree.
|
|
4397
|
+
* However, if a component is created after its parent is mounted, the parent
|
|
4398
|
+
* won't trigger that mount animation so the child needs to.
|
|
4399
|
+
*
|
|
4400
|
+
* TODO: This might be better replaced with a method isParentMounted
|
|
4414
4401
|
*/
|
|
4415
|
-
|
|
4416
|
-
// Internal methods ========================
|
|
4402
|
+
manuallyAnimateOnMount: Boolean(parent === null || parent === void 0 ? void 0 : parent.isMounted()),
|
|
4417
4403
|
/**
|
|
4418
|
-
*
|
|
4419
|
-
*
|
|
4404
|
+
* This can be set by AnimatePresence to force components that mount
|
|
4405
|
+
* at the same time as it to mount as if they have initial={false} set.
|
|
4420
4406
|
*/
|
|
4421
|
-
|
|
4407
|
+
blockInitialAnimation,
|
|
4422
4408
|
/**
|
|
4423
|
-
*
|
|
4424
|
-
*
|
|
4409
|
+
* Determine whether this component has mounted yet. This is mostly used
|
|
4410
|
+
* by variant children to determine whether they need to trigger their
|
|
4411
|
+
* own animations on mount.
|
|
4425
4412
|
*/
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4413
|
+
isMounted: () => Boolean(instance), mount(newInstance) {
|
|
4414
|
+
isMounted = true;
|
|
4415
|
+
instance = element.current = newInstance;
|
|
4416
|
+
if (element.projection) {
|
|
4417
|
+
element.projection.mount(newInstance);
|
|
4418
|
+
}
|
|
4419
|
+
if (isVariantNode && parent && !isControllingVariants) {
|
|
4420
|
+
removeFromVariantTree = parent === null || parent === void 0 ? void 0 : parent.addVariantChild(element);
|
|
4421
|
+
}
|
|
4422
|
+
values.forEach((value, key) => bindToMotionValue(key, value));
|
|
4423
|
+
parent === null || parent === void 0 ? void 0 : parent.children.add(element);
|
|
4424
|
+
element.setProps(props);
|
|
4425
|
+
},
|
|
4438
4426
|
/**
|
|
4439
4427
|
*
|
|
4440
4428
|
*/
|
|
4441
|
-
|
|
4442
|
-
var
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4429
|
+
unmount() {
|
|
4430
|
+
var _a;
|
|
4431
|
+
(_a = element.projection) === null || _a === void 0 ? void 0 : _a.unmount();
|
|
4432
|
+
cancelSync.update(update);
|
|
4433
|
+
cancelSync.render(render);
|
|
4434
|
+
valueSubscriptions.forEach((remove) => remove());
|
|
4435
|
+
removeFromVariantTree === null || removeFromVariantTree === void 0 ? void 0 : removeFromVariantTree();
|
|
4436
|
+
parent === null || parent === void 0 ? void 0 : parent.children.delete(element);
|
|
4437
|
+
lifecycles.clearAllListeners();
|
|
4438
|
+
instance = undefined;
|
|
4439
|
+
isMounted = false;
|
|
4440
|
+
},
|
|
4452
4441
|
/**
|
|
4453
|
-
*
|
|
4454
|
-
* aren't yet bound to the element, as this would technically be impure.
|
|
4455
|
-
* However, we iterate through the motion values and set them to the
|
|
4456
|
-
* initial values for this component.
|
|
4457
|
-
*
|
|
4458
|
-
* TODO: This is impure and we should look at changing this to run on mount.
|
|
4459
|
-
* Doing so will break some tests but this isn't neccessarily a breaking change,
|
|
4460
|
-
* more a reflection of the test.
|
|
4442
|
+
* Add a child visual element to our set of children.
|
|
4461
4443
|
*/
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
if (
|
|
4466
|
-
|
|
4444
|
+
addVariantChild(child) {
|
|
4445
|
+
var _a;
|
|
4446
|
+
const closestVariantNode = element.getClosestVariantNode();
|
|
4447
|
+
if (closestVariantNode) {
|
|
4448
|
+
(_a = closestVariantNode.variantChildren) === null || _a === void 0 ? void 0 : _a.add(child);
|
|
4449
|
+
return () => closestVariantNode.variantChildren.delete(child);
|
|
4467
4450
|
}
|
|
4468
|
-
}
|
|
4469
|
-
|
|
4470
|
-
* Determine what role this visual element should take in the variant tree.
|
|
4471
|
-
*/
|
|
4472
|
-
var isControllingVariants = checkIfControllingVariants(props);
|
|
4473
|
-
var isVariantNode = checkIfVariantNode(props);
|
|
4474
|
-
var element = __assign(__assign({ treeType: treeType,
|
|
4475
|
-
/**
|
|
4476
|
-
* This is a mirror of the internal instance prop, which keeps
|
|
4477
|
-
* VisualElement type-compatible with React's RefObject.
|
|
4478
|
-
*/
|
|
4479
|
-
current: null,
|
|
4480
|
-
/**
|
|
4481
|
-
* The depth of this visual element within the visual element tree.
|
|
4482
|
-
*/
|
|
4483
|
-
depth: parent ? parent.depth + 1 : 0, parent: parent, children: new Set(),
|
|
4484
|
-
/**
|
|
4485
|
-
*
|
|
4486
|
-
*/
|
|
4487
|
-
presenceId: presenceId, shouldReduceMotion: shouldReduceMotion,
|
|
4488
|
-
/**
|
|
4489
|
-
* If this component is part of the variant tree, it should track
|
|
4490
|
-
* any children that are also part of the tree. This is essentially
|
|
4491
|
-
* a shadow tree to simplify logic around how to stagger over children.
|
|
4492
|
-
*/
|
|
4493
|
-
variantChildren: isVariantNode ? new Set() : undefined,
|
|
4494
|
-
/**
|
|
4495
|
-
* Whether this instance is visible. This can be changed imperatively
|
|
4496
|
-
* by the projection tree, is analogous to CSS's visibility in that
|
|
4497
|
-
* hidden elements should take up layout, and needs enacting by the configured
|
|
4498
|
-
* render function.
|
|
4499
|
-
*/
|
|
4500
|
-
isVisible: undefined,
|
|
4501
|
-
/**
|
|
4502
|
-
* Normally, if a component is controlled by a parent's variants, it can
|
|
4503
|
-
* rely on that ancestor to trigger animations further down the tree.
|
|
4504
|
-
* However, if a component is created after its parent is mounted, the parent
|
|
4505
|
-
* won't trigger that mount animation so the child needs to.
|
|
4506
|
-
*
|
|
4507
|
-
* TODO: This might be better replaced with a method isParentMounted
|
|
4508
|
-
*/
|
|
4509
|
-
manuallyAnimateOnMount: Boolean(parent === null || parent === void 0 ? void 0 : parent.isMounted()),
|
|
4510
|
-
/**
|
|
4511
|
-
* This can be set by AnimatePresence to force components that mount
|
|
4512
|
-
* at the same time as it to mount as if they have initial={false} set.
|
|
4513
|
-
*/
|
|
4514
|
-
blockInitialAnimation: blockInitialAnimation,
|
|
4515
|
-
/**
|
|
4516
|
-
* Determine whether this component has mounted yet. This is mostly used
|
|
4517
|
-
* by variant children to determine whether they need to trigger their
|
|
4518
|
-
* own animations on mount.
|
|
4519
|
-
*/
|
|
4520
|
-
isMounted: function () { return Boolean(instance); }, mount: function (newInstance) {
|
|
4521
|
-
isMounted = true;
|
|
4522
|
-
instance = element.current = newInstance;
|
|
4523
|
-
if (element.projection) {
|
|
4524
|
-
element.projection.mount(newInstance);
|
|
4525
|
-
}
|
|
4526
|
-
if (isVariantNode && parent && !isControllingVariants) {
|
|
4527
|
-
removeFromVariantTree = parent === null || parent === void 0 ? void 0 : parent.addVariantChild(element);
|
|
4528
|
-
}
|
|
4529
|
-
values.forEach(function (value, key) { return bindToMotionValue(key, value); });
|
|
4530
|
-
parent === null || parent === void 0 ? void 0 : parent.children.add(element);
|
|
4531
|
-
element.setProps(props);
|
|
4532
|
-
},
|
|
4533
|
-
/**
|
|
4534
|
-
*
|
|
4535
|
-
*/
|
|
4536
|
-
unmount: function () {
|
|
4537
|
-
var _a;
|
|
4538
|
-
(_a = element.projection) === null || _a === void 0 ? void 0 : _a.unmount();
|
|
4539
|
-
cancelSync.update(update);
|
|
4540
|
-
cancelSync.render(render);
|
|
4541
|
-
valueSubscriptions.forEach(function (remove) { return remove(); });
|
|
4542
|
-
removeFromVariantTree === null || removeFromVariantTree === void 0 ? void 0 : removeFromVariantTree();
|
|
4543
|
-
parent === null || parent === void 0 ? void 0 : parent.children.delete(element);
|
|
4544
|
-
lifecycles.clearAllListeners();
|
|
4545
|
-
instance = undefined;
|
|
4546
|
-
isMounted = false;
|
|
4547
|
-
},
|
|
4548
|
-
/**
|
|
4549
|
-
* Add a child visual element to our set of children.
|
|
4550
|
-
*/
|
|
4551
|
-
addVariantChild: function (child) {
|
|
4552
|
-
var _a;
|
|
4553
|
-
var closestVariantNode = element.getClosestVariantNode();
|
|
4554
|
-
if (closestVariantNode) {
|
|
4555
|
-
(_a = closestVariantNode.variantChildren) === null || _a === void 0 ? void 0 : _a.add(child);
|
|
4556
|
-
return function () {
|
|
4557
|
-
return closestVariantNode.variantChildren.delete(child);
|
|
4558
|
-
};
|
|
4559
|
-
}
|
|
4560
|
-
}, sortNodePosition: function (other) {
|
|
4561
|
-
/**
|
|
4562
|
-
* If these nodes aren't even of the same type we can't compare their depth.
|
|
4563
|
-
*/
|
|
4564
|
-
if (!sortNodePosition || treeType !== other.treeType)
|
|
4565
|
-
return 0;
|
|
4566
|
-
return sortNodePosition(element.getInstance(), other.getInstance());
|
|
4567
|
-
},
|
|
4568
|
-
/**
|
|
4569
|
-
* Returns the closest variant node in the tree starting from
|
|
4570
|
-
* this visual element.
|
|
4571
|
-
*/
|
|
4572
|
-
getClosestVariantNode: function () {
|
|
4573
|
-
return isVariantNode ? element : parent === null || parent === void 0 ? void 0 : parent.getClosestVariantNode();
|
|
4574
|
-
},
|
|
4575
|
-
/**
|
|
4576
|
-
* Expose the latest layoutId prop.
|
|
4577
|
-
*/
|
|
4578
|
-
getLayoutId: function () { return props.layoutId; },
|
|
4579
|
-
/**
|
|
4580
|
-
* Returns the current instance.
|
|
4581
|
-
*/
|
|
4582
|
-
getInstance: function () { return instance; },
|
|
4583
|
-
/**
|
|
4584
|
-
* Get/set the latest static values.
|
|
4585
|
-
*/
|
|
4586
|
-
getStaticValue: function (key) { return latestValues[key]; }, setStaticValue: function (key, value) { return (latestValues[key] = value); },
|
|
4587
|
-
/**
|
|
4588
|
-
* Returns the latest motion value state. Currently only used to take
|
|
4589
|
-
* a snapshot of the visual element - perhaps this can return the whole
|
|
4590
|
-
* visual state
|
|
4591
|
-
*/
|
|
4592
|
-
getLatestValues: function () { return latestValues; },
|
|
4451
|
+
},
|
|
4452
|
+
sortNodePosition(other) {
|
|
4593
4453
|
/**
|
|
4594
|
-
*
|
|
4595
|
-
* a render to reflect these changes.
|
|
4454
|
+
* If these nodes aren't even of the same type we can't compare their depth.
|
|
4596
4455
|
*/
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4456
|
+
if (!sortNodePosition || treeType !== other.treeType)
|
|
4457
|
+
return 0;
|
|
4458
|
+
return sortNodePosition(element.getInstance(), other.getInstance());
|
|
4459
|
+
},
|
|
4460
|
+
/**
|
|
4461
|
+
* Returns the closest variant node in the tree starting from
|
|
4462
|
+
* this visual element.
|
|
4463
|
+
*/
|
|
4464
|
+
getClosestVariantNode: () => isVariantNode ? element : parent === null || parent === void 0 ? void 0 : parent.getClosestVariantNode(),
|
|
4465
|
+
/**
|
|
4466
|
+
* Expose the latest layoutId prop.
|
|
4467
|
+
*/
|
|
4468
|
+
getLayoutId: () => props.layoutId,
|
|
4469
|
+
/**
|
|
4470
|
+
* Returns the current instance.
|
|
4471
|
+
*/
|
|
4472
|
+
getInstance: () => instance,
|
|
4473
|
+
/**
|
|
4474
|
+
* Get/set the latest static values.
|
|
4475
|
+
*/
|
|
4476
|
+
getStaticValue: (key) => latestValues[key], setStaticValue: (key, value) => (latestValues[key] = value),
|
|
4477
|
+
/**
|
|
4478
|
+
* Returns the latest motion value state. Currently only used to take
|
|
4479
|
+
* a snapshot of the visual element - perhaps this can return the whole
|
|
4480
|
+
* visual state
|
|
4481
|
+
*/
|
|
4482
|
+
getLatestValues: () => latestValues,
|
|
4483
|
+
/**
|
|
4484
|
+
* Set the visiblity of the visual element. If it's changed, schedule
|
|
4485
|
+
* a render to reflect these changes.
|
|
4486
|
+
*/
|
|
4487
|
+
setVisibility(visibility) {
|
|
4488
|
+
if (element.isVisible === visibility)
|
|
4489
|
+
return;
|
|
4490
|
+
element.isVisible = visibility;
|
|
4491
|
+
element.scheduleRender();
|
|
4492
|
+
},
|
|
4493
|
+
/**
|
|
4494
|
+
* Make a target animatable by Popmotion. For instance, if we're
|
|
4495
|
+
* trying to animate width from 100px to 100vw we need to measure 100vw
|
|
4496
|
+
* in pixels to determine what we really need to animate to. This is also
|
|
4497
|
+
* pluggable to support Framer's custom value types like Color,
|
|
4498
|
+
* and CSS variables.
|
|
4499
|
+
*/
|
|
4500
|
+
makeTargetAnimatable(target, canMutate = true) {
|
|
4501
|
+
return makeTargetAnimatable(element, target, props, canMutate);
|
|
4502
|
+
},
|
|
4503
|
+
/**
|
|
4504
|
+
* Measure the current viewport box with or without transforms.
|
|
4505
|
+
* Only measures axis-aligned boxes, rotate and skew must be manually
|
|
4506
|
+
* removed with a re-render to work.
|
|
4507
|
+
*/
|
|
4508
|
+
measureViewportBox() {
|
|
4509
|
+
return measureViewportBox(instance, props);
|
|
4510
|
+
},
|
|
4511
|
+
// Motion values ========================
|
|
4512
|
+
/**
|
|
4513
|
+
* Add a motion value and bind it to this visual element.
|
|
4514
|
+
*/
|
|
4515
|
+
addValue(key, value) {
|
|
4516
|
+
// Remove existing value if it exists
|
|
4517
|
+
if (element.hasValue(key))
|
|
4518
|
+
element.removeValue(key);
|
|
4519
|
+
values.set(key, value);
|
|
4520
|
+
latestValues[key] = value.get();
|
|
4521
|
+
bindToMotionValue(key, value);
|
|
4522
|
+
},
|
|
4523
|
+
/**
|
|
4524
|
+
* Remove a motion value and unbind any active subscriptions.
|
|
4525
|
+
*/
|
|
4526
|
+
removeValue(key) {
|
|
4527
|
+
var _a;
|
|
4528
|
+
values.delete(key);
|
|
4529
|
+
(_a = valueSubscriptions.get(key)) === null || _a === void 0 ? void 0 : _a();
|
|
4530
|
+
valueSubscriptions.delete(key);
|
|
4531
|
+
delete latestValues[key];
|
|
4532
|
+
removeValueFromRenderState(key, renderState);
|
|
4533
|
+
},
|
|
4534
|
+
/**
|
|
4535
|
+
* Check whether we have a motion value for this key
|
|
4536
|
+
*/
|
|
4537
|
+
hasValue: (key) => values.has(key),
|
|
4538
|
+
/**
|
|
4539
|
+
* Get a motion value for this key. If called with a default
|
|
4540
|
+
* value, we'll create one if none exists.
|
|
4541
|
+
*/
|
|
4542
|
+
getValue(key, defaultValue) {
|
|
4543
|
+
let value = values.get(key);
|
|
4544
|
+
if (value === undefined && defaultValue !== undefined) {
|
|
4545
|
+
value = motionValue(defaultValue);
|
|
4546
|
+
element.addValue(key, value);
|
|
4547
|
+
}
|
|
4548
|
+
return value;
|
|
4549
|
+
},
|
|
4550
|
+
/**
|
|
4551
|
+
* Iterate over our motion values.
|
|
4552
|
+
*/
|
|
4553
|
+
forEachValue: (callback) => values.forEach(callback),
|
|
4554
|
+
/**
|
|
4555
|
+
* If we're trying to animate to a previously unencountered value,
|
|
4556
|
+
* we need to check for it in our state and as a last resort read it
|
|
4557
|
+
* directly from the instance (which might have performance implications).
|
|
4558
|
+
*/
|
|
4559
|
+
readValue: (key) => {
|
|
4560
|
+
var _a;
|
|
4561
|
+
return (_a = latestValues[key]) !== null && _a !== void 0 ? _a : readValueFromInstance(instance, key, options);
|
|
4562
|
+
},
|
|
4563
|
+
/**
|
|
4564
|
+
* Set the base target to later animate back to. This is currently
|
|
4565
|
+
* only hydrated on creation and when we first read a value.
|
|
4566
|
+
*/
|
|
4567
|
+
setBaseTarget(key, value) {
|
|
4568
|
+
baseTarget[key] = value;
|
|
4569
|
+
},
|
|
4570
|
+
/**
|
|
4571
|
+
* Find the base target for a value thats been removed from all animation
|
|
4572
|
+
* props.
|
|
4573
|
+
*/
|
|
4574
|
+
getBaseTarget(key) {
|
|
4575
|
+
if (getBaseTarget) {
|
|
4576
|
+
const target = getBaseTarget(props, key);
|
|
4577
|
+
if (target !== undefined && !isMotionValue(target))
|
|
4578
|
+
return target;
|
|
4579
|
+
}
|
|
4580
|
+
return baseTarget[key];
|
|
4581
|
+
} }, lifecycles), {
|
|
4582
|
+
/**
|
|
4583
|
+
* Build the renderer state based on the latest visual state.
|
|
4584
|
+
*/
|
|
4585
|
+
build() {
|
|
4586
|
+
triggerBuild();
|
|
4587
|
+
return renderState;
|
|
4588
|
+
},
|
|
4589
|
+
/**
|
|
4590
|
+
* Schedule a render on the next animation frame.
|
|
4591
|
+
*/
|
|
4592
|
+
scheduleRender() {
|
|
4593
|
+
sync.render(render, false, true);
|
|
4594
|
+
},
|
|
4595
|
+
/**
|
|
4596
|
+
* Synchronously fire render. It's prefered that we batch renders but
|
|
4597
|
+
* in many circumstances, like layout measurement, we need to run this
|
|
4598
|
+
* synchronously. However in those instances other measures should be taken
|
|
4599
|
+
* to batch reads/writes.
|
|
4600
|
+
*/
|
|
4601
|
+
syncRender: render,
|
|
4602
|
+
/**
|
|
4603
|
+
* Update the provided props. Ensure any newly-added motion values are
|
|
4604
|
+
* added to our map, old ones removed, and listeners updated.
|
|
4605
|
+
*/
|
|
4606
|
+
setProps(newProps) {
|
|
4607
|
+
if (newProps.transformTemplate || props.transformTemplate) {
|
|
4601
4608
|
element.scheduleRender();
|
|
4602
|
-
}
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
if (element.hasValue(key))
|
|
4629
|
-
element.removeValue(key);
|
|
4630
|
-
values.set(key, value);
|
|
4631
|
-
latestValues[key] = value.get();
|
|
4632
|
-
bindToMotionValue(key, value);
|
|
4633
|
-
},
|
|
4634
|
-
/**
|
|
4635
|
-
* Remove a motion value and unbind any active subscriptions.
|
|
4636
|
-
*/
|
|
4637
|
-
removeValue: function (key) {
|
|
4638
|
-
var _a;
|
|
4639
|
-
values.delete(key);
|
|
4640
|
-
(_a = valueSubscriptions.get(key)) === null || _a === void 0 ? void 0 : _a();
|
|
4641
|
-
valueSubscriptions.delete(key);
|
|
4642
|
-
delete latestValues[key];
|
|
4643
|
-
removeValueFromRenderState(key, renderState);
|
|
4644
|
-
},
|
|
4645
|
-
/**
|
|
4646
|
-
* Check whether we have a motion value for this key
|
|
4647
|
-
*/
|
|
4648
|
-
hasValue: function (key) { return values.has(key); },
|
|
4649
|
-
/**
|
|
4650
|
-
* Get a motion value for this key. If called with a default
|
|
4651
|
-
* value, we'll create one if none exists.
|
|
4652
|
-
*/
|
|
4653
|
-
getValue: function (key, defaultValue) {
|
|
4654
|
-
var value = values.get(key);
|
|
4655
|
-
if (value === undefined && defaultValue !== undefined) {
|
|
4656
|
-
value = motionValue(defaultValue);
|
|
4657
|
-
element.addValue(key, value);
|
|
4658
|
-
}
|
|
4659
|
-
return value;
|
|
4660
|
-
},
|
|
4661
|
-
/**
|
|
4662
|
-
* Iterate over our motion values.
|
|
4663
|
-
*/
|
|
4664
|
-
forEachValue: function (callback) { return values.forEach(callback); },
|
|
4665
|
-
/**
|
|
4666
|
-
* If we're trying to animate to a previously unencountered value,
|
|
4667
|
-
* we need to check for it in our state and as a last resort read it
|
|
4668
|
-
* directly from the instance (which might have performance implications).
|
|
4669
|
-
*/
|
|
4670
|
-
readValue: function (key) {
|
|
4671
|
-
var _a;
|
|
4672
|
-
return (_a = latestValues[key]) !== null && _a !== void 0 ? _a : readValueFromInstance(instance, key, options);
|
|
4673
|
-
},
|
|
4674
|
-
/**
|
|
4675
|
-
* Set the base target to later animate back to. This is currently
|
|
4676
|
-
* only hydrated on creation and when we first read a value.
|
|
4677
|
-
*/
|
|
4678
|
-
setBaseTarget: function (key, value) {
|
|
4679
|
-
baseTarget[key] = value;
|
|
4680
|
-
},
|
|
4681
|
-
/**
|
|
4682
|
-
* Find the base target for a value thats been removed from all animation
|
|
4683
|
-
* props.
|
|
4684
|
-
*/
|
|
4685
|
-
getBaseTarget: function (key) {
|
|
4686
|
-
if (getBaseTarget) {
|
|
4687
|
-
var target = getBaseTarget(props, key);
|
|
4688
|
-
if (target !== undefined && !isMotionValue(target))
|
|
4689
|
-
return target;
|
|
4690
|
-
}
|
|
4691
|
-
return baseTarget[key];
|
|
4692
|
-
} }, lifecycles), {
|
|
4693
|
-
/**
|
|
4694
|
-
* Build the renderer state based on the latest visual state.
|
|
4695
|
-
*/
|
|
4696
|
-
build: function () {
|
|
4697
|
-
triggerBuild();
|
|
4698
|
-
return renderState;
|
|
4699
|
-
},
|
|
4700
|
-
/**
|
|
4701
|
-
* Schedule a render on the next animation frame.
|
|
4702
|
-
*/
|
|
4703
|
-
scheduleRender: function () {
|
|
4704
|
-
sync.render(render, false, true);
|
|
4705
|
-
},
|
|
4706
|
-
/**
|
|
4707
|
-
* Synchronously fire render. It's prefered that we batch renders but
|
|
4708
|
-
* in many circumstances, like layout measurement, we need to run this
|
|
4709
|
-
* synchronously. However in those instances other measures should be taken
|
|
4710
|
-
* to batch reads/writes.
|
|
4711
|
-
*/
|
|
4712
|
-
syncRender: render,
|
|
4713
|
-
/**
|
|
4714
|
-
* Update the provided props. Ensure any newly-added motion values are
|
|
4715
|
-
* added to our map, old ones removed, and listeners updated.
|
|
4716
|
-
*/
|
|
4717
|
-
setProps: function (newProps) {
|
|
4718
|
-
if (newProps.transformTemplate || props.transformTemplate) {
|
|
4719
|
-
element.scheduleRender();
|
|
4720
|
-
}
|
|
4721
|
-
props = newProps;
|
|
4722
|
-
lifecycles.updatePropListeners(newProps);
|
|
4723
|
-
prevMotionValues = updateMotionValuesFromProps(element, scrapeMotionValuesFromProps(props), prevMotionValues);
|
|
4724
|
-
}, getProps: function () { return props; },
|
|
4725
|
-
// Variants ==============================
|
|
4726
|
-
/**
|
|
4727
|
-
* Returns the variant definition with a given name.
|
|
4728
|
-
*/
|
|
4729
|
-
getVariant: function (name) { var _a; return (_a = props.variants) === null || _a === void 0 ? void 0 : _a[name]; },
|
|
4730
|
-
/**
|
|
4731
|
-
* Returns the defined default transition on this component.
|
|
4732
|
-
*/
|
|
4733
|
-
getDefaultTransition: function () { return props.transition; }, getTransformPagePoint: function () {
|
|
4734
|
-
return props.transformPagePoint;
|
|
4735
|
-
},
|
|
4736
|
-
/**
|
|
4737
|
-
* Used by child variant nodes to get the closest ancestor variant props.
|
|
4738
|
-
*/
|
|
4739
|
-
getVariantContext: function (startAtParent) {
|
|
4740
|
-
if (startAtParent === void 0) { startAtParent = false; }
|
|
4741
|
-
if (startAtParent)
|
|
4742
|
-
return parent === null || parent === void 0 ? void 0 : parent.getVariantContext();
|
|
4743
|
-
if (!isControllingVariants) {
|
|
4744
|
-
var context_1 = (parent === null || parent === void 0 ? void 0 : parent.getVariantContext()) || {};
|
|
4745
|
-
if (props.initial !== undefined) {
|
|
4746
|
-
context_1.initial = props.initial;
|
|
4747
|
-
}
|
|
4748
|
-
return context_1;
|
|
4749
|
-
}
|
|
4750
|
-
var context = {};
|
|
4751
|
-
for (var i = 0; i < numVariantProps; i++) {
|
|
4752
|
-
var name_1 = variantProps[i];
|
|
4753
|
-
var prop = props[name_1];
|
|
4754
|
-
if (isVariantLabel(prop) || prop === false) {
|
|
4755
|
-
context[name_1] = prop;
|
|
4756
|
-
}
|
|
4609
|
+
}
|
|
4610
|
+
props = newProps;
|
|
4611
|
+
lifecycles.updatePropListeners(newProps);
|
|
4612
|
+
prevMotionValues = updateMotionValuesFromProps(element, scrapeMotionValuesFromProps(props), prevMotionValues);
|
|
4613
|
+
}, getProps: () => props,
|
|
4614
|
+
// Variants ==============================
|
|
4615
|
+
/**
|
|
4616
|
+
* Returns the variant definition with a given name.
|
|
4617
|
+
*/
|
|
4618
|
+
getVariant: (name) => { var _a; return (_a = props.variants) === null || _a === void 0 ? void 0 : _a[name]; },
|
|
4619
|
+
/**
|
|
4620
|
+
* Returns the defined default transition on this component.
|
|
4621
|
+
*/
|
|
4622
|
+
getDefaultTransition: () => props.transition, getTransformPagePoint: () => {
|
|
4623
|
+
return props.transformPagePoint;
|
|
4624
|
+
},
|
|
4625
|
+
/**
|
|
4626
|
+
* Used by child variant nodes to get the closest ancestor variant props.
|
|
4627
|
+
*/
|
|
4628
|
+
getVariantContext(startAtParent = false) {
|
|
4629
|
+
if (startAtParent)
|
|
4630
|
+
return parent === null || parent === void 0 ? void 0 : parent.getVariantContext();
|
|
4631
|
+
if (!isControllingVariants) {
|
|
4632
|
+
const context = (parent === null || parent === void 0 ? void 0 : parent.getVariantContext()) || {};
|
|
4633
|
+
if (props.initial !== undefined) {
|
|
4634
|
+
context.initial = props.initial;
|
|
4757
4635
|
}
|
|
4758
4636
|
return context;
|
|
4759
|
-
}
|
|
4760
|
-
|
|
4761
|
-
|
|
4637
|
+
}
|
|
4638
|
+
const context = {};
|
|
4639
|
+
for (let i = 0; i < numVariantProps; i++) {
|
|
4640
|
+
const name = variantProps[i];
|
|
4641
|
+
const prop = props[name];
|
|
4642
|
+
if (isVariantLabel(prop) || prop === false) {
|
|
4643
|
+
context[name] = prop;
|
|
4644
|
+
}
|
|
4645
|
+
}
|
|
4646
|
+
return context;
|
|
4647
|
+
} });
|
|
4648
|
+
return element;
|
|
4762
4649
|
};
|
|
4763
|
-
|
|
4764
|
-
|
|
4650
|
+
const variantProps = ["initial", ...variantPriorityOrder];
|
|
4651
|
+
const numVariantProps = variantProps.length;
|
|
4765
4652
|
|
|
4766
4653
|
/**
|
|
4767
4654
|
* Returns true if the provided key is a CSS variable
|
|
@@ -4773,7 +4660,7 @@
|
|
|
4773
4660
|
/**
|
|
4774
4661
|
* Provided a value and a ValueType, returns the value as that value type.
|
|
4775
4662
|
*/
|
|
4776
|
-
|
|
4663
|
+
const getValueAsType = (value, type) => {
|
|
4777
4664
|
return type && typeof value === "number"
|
|
4778
4665
|
? type.transform(value)
|
|
4779
4666
|
: value;
|
|
@@ -4781,24 +4668,24 @@
|
|
|
4781
4668
|
|
|
4782
4669
|
function buildHTMLStyles(state, latestValues, options, transformTemplate) {
|
|
4783
4670
|
var _a;
|
|
4784
|
-
|
|
4671
|
+
const { style, vars, transform, transformKeys, transformOrigin } = state;
|
|
4785
4672
|
// Empty the transformKeys array. As we're throwing out refs to its items
|
|
4786
4673
|
// this might not be as cheap as suspected. Maybe using the array as a buffer
|
|
4787
4674
|
// with a manual incrementation would be better.
|
|
4788
4675
|
transformKeys.length = 0;
|
|
4789
4676
|
// Track whether we encounter any transform or transformOrigin values.
|
|
4790
|
-
|
|
4791
|
-
|
|
4677
|
+
let hasTransform = false;
|
|
4678
|
+
let hasTransformOrigin = false;
|
|
4792
4679
|
// Does the calculated transform essentially equal "none"?
|
|
4793
|
-
|
|
4680
|
+
let transformIsNone = true;
|
|
4794
4681
|
/**
|
|
4795
4682
|
* Loop over all our latest animated values and decide whether to handle them
|
|
4796
4683
|
* as a style or CSS variable.
|
|
4797
4684
|
*
|
|
4798
4685
|
* Transforms and transform origins are kept seperately for further processing.
|
|
4799
4686
|
*/
|
|
4800
|
-
for (
|
|
4801
|
-
|
|
4687
|
+
for (const key in latestValues) {
|
|
4688
|
+
const value = latestValues[key];
|
|
4802
4689
|
/**
|
|
4803
4690
|
* If this is a CSS variable we don't do any further processing.
|
|
4804
4691
|
*/
|
|
@@ -4807,8 +4694,8 @@
|
|
|
4807
4694
|
continue;
|
|
4808
4695
|
}
|
|
4809
4696
|
// Convert the value to its default value type, ie 0 -> "0px"
|
|
4810
|
-
|
|
4811
|
-
|
|
4697
|
+
const valueType = numberValueTypes[key];
|
|
4698
|
+
const valueAsType = getValueAsType(value, valueType);
|
|
4812
4699
|
if (isTransformProp(key)) {
|
|
4813
4700
|
// If this is a transform, flag to enable further transform processing
|
|
4814
4701
|
hasTransform = true;
|
|
@@ -4844,7 +4731,9 @@
|
|
|
4844
4731
|
}
|
|
4845
4732
|
}
|
|
4846
4733
|
|
|
4847
|
-
|
|
4734
|
+
const isBrowser = typeof document !== "undefined";
|
|
4735
|
+
|
|
4736
|
+
const positionalKeys = new Set([
|
|
4848
4737
|
"width",
|
|
4849
4738
|
"height",
|
|
4850
4739
|
"top",
|
|
@@ -4854,19 +4743,17 @@
|
|
|
4854
4743
|
"x",
|
|
4855
4744
|
"y",
|
|
4856
4745
|
]);
|
|
4857
|
-
|
|
4858
|
-
|
|
4746
|
+
const isPositionalKey = (key) => positionalKeys.has(key);
|
|
4747
|
+
const hasPositionalKey = (target) => {
|
|
4859
4748
|
return Object.keys(target).some(isPositionalKey);
|
|
4860
4749
|
};
|
|
4861
|
-
|
|
4750
|
+
const setAndResetVelocity = (value, to) => {
|
|
4862
4751
|
// Looks odd but setting it twice doesn't render, it'll just
|
|
4863
4752
|
// set both prev and current to the latest value
|
|
4864
4753
|
value.set(to, false);
|
|
4865
4754
|
value.set(to);
|
|
4866
4755
|
};
|
|
4867
|
-
|
|
4868
|
-
return v === number || v === px;
|
|
4869
|
-
};
|
|
4756
|
+
const isNumOrPxType = (v) => v === number || v === px;
|
|
4870
4757
|
var BoundingBoxDimension;
|
|
4871
4758
|
(function (BoundingBoxDimension) {
|
|
4872
4759
|
BoundingBoxDimension["width"] = "width";
|
|
@@ -4876,35 +4763,30 @@
|
|
|
4876
4763
|
BoundingBoxDimension["top"] = "top";
|
|
4877
4764
|
BoundingBoxDimension["bottom"] = "bottom";
|
|
4878
4765
|
})(BoundingBoxDimension || (BoundingBoxDimension = {}));
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4766
|
+
const getPosFromMatrix = (matrix, pos) => parseFloat(matrix.split(", ")[pos]);
|
|
4767
|
+
const getTranslateFromMatrix = (pos2, pos3) => (_bbox, { transform }) => {
|
|
4768
|
+
if (transform === "none" || !transform)
|
|
4769
|
+
return 0;
|
|
4770
|
+
const matrix3d = transform.match(/^matrix3d\((.+)\)$/);
|
|
4771
|
+
if (matrix3d) {
|
|
4772
|
+
return getPosFromMatrix(matrix3d[1], pos3);
|
|
4773
|
+
}
|
|
4774
|
+
else {
|
|
4775
|
+
const matrix = transform.match(/^matrix\((.+)\)$/);
|
|
4776
|
+
if (matrix) {
|
|
4777
|
+
return getPosFromMatrix(matrix[1], pos2);
|
|
4890
4778
|
}
|
|
4891
4779
|
else {
|
|
4892
|
-
|
|
4893
|
-
if (matrix) {
|
|
4894
|
-
return getPosFromMatrix(matrix[1], pos2);
|
|
4895
|
-
}
|
|
4896
|
-
else {
|
|
4897
|
-
return 0;
|
|
4898
|
-
}
|
|
4780
|
+
return 0;
|
|
4899
4781
|
}
|
|
4900
|
-
}
|
|
4782
|
+
}
|
|
4901
4783
|
};
|
|
4902
|
-
|
|
4903
|
-
|
|
4784
|
+
const transformKeys = new Set(["x", "y", "z"]);
|
|
4785
|
+
const nonTranslationalTransformKeys = transformProps.filter((key) => !transformKeys.has(key));
|
|
4904
4786
|
function removeNonTranslationalTransform(visualElement) {
|
|
4905
|
-
|
|
4906
|
-
nonTranslationalTransformKeys.forEach(
|
|
4907
|
-
|
|
4787
|
+
const removedTransforms = [];
|
|
4788
|
+
nonTranslationalTransformKeys.forEach((key) => {
|
|
4789
|
+
const value = visualElement.getValue(key);
|
|
4908
4790
|
if (value !== undefined) {
|
|
4909
4791
|
removedTransforms.push([key, value.get()]);
|
|
4910
4792
|
value.set(key.startsWith("scale") ? 1 : 0);
|
|
@@ -4915,46 +4797,24 @@
|
|
|
4915
4797
|
visualElement.syncRender();
|
|
4916
4798
|
return removedTransforms;
|
|
4917
4799
|
}
|
|
4918
|
-
|
|
4800
|
+
const positionalValues = {
|
|
4919
4801
|
// Dimensions
|
|
4920
|
-
width:
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
},
|
|
4925
|
-
|
|
4926
|
-
var y = _a.y;
|
|
4927
|
-
var _c = _b.paddingTop, paddingTop = _c === void 0 ? "0" : _c, _d = _b.paddingBottom, paddingBottom = _d === void 0 ? "0" : _d;
|
|
4928
|
-
return y.max - y.min - parseFloat(paddingTop) - parseFloat(paddingBottom);
|
|
4929
|
-
},
|
|
4930
|
-
top: function (_bbox, _a) {
|
|
4931
|
-
var top = _a.top;
|
|
4932
|
-
return parseFloat(top);
|
|
4933
|
-
},
|
|
4934
|
-
left: function (_bbox, _a) {
|
|
4935
|
-
var left = _a.left;
|
|
4936
|
-
return parseFloat(left);
|
|
4937
|
-
},
|
|
4938
|
-
bottom: function (_a, _b) {
|
|
4939
|
-
var y = _a.y;
|
|
4940
|
-
var top = _b.top;
|
|
4941
|
-
return parseFloat(top) + (y.max - y.min);
|
|
4942
|
-
},
|
|
4943
|
-
right: function (_a, _b) {
|
|
4944
|
-
var x = _a.x;
|
|
4945
|
-
var left = _b.left;
|
|
4946
|
-
return parseFloat(left) + (x.max - x.min);
|
|
4947
|
-
},
|
|
4802
|
+
width: ({ x }, { paddingLeft = "0", paddingRight = "0" }) => x.max - x.min - parseFloat(paddingLeft) - parseFloat(paddingRight),
|
|
4803
|
+
height: ({ y }, { paddingTop = "0", paddingBottom = "0" }) => y.max - y.min - parseFloat(paddingTop) - parseFloat(paddingBottom),
|
|
4804
|
+
top: (_bbox, { top }) => parseFloat(top),
|
|
4805
|
+
left: (_bbox, { left }) => parseFloat(left),
|
|
4806
|
+
bottom: ({ y }, { top }) => parseFloat(top) + (y.max - y.min),
|
|
4807
|
+
right: ({ x }, { left }) => parseFloat(left) + (x.max - x.min),
|
|
4948
4808
|
// Transform
|
|
4949
4809
|
x: getTranslateFromMatrix(4, 13),
|
|
4950
4810
|
y: getTranslateFromMatrix(5, 14),
|
|
4951
4811
|
};
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
4812
|
+
const convertChangedValueTypes = (target, visualElement, changedKeys) => {
|
|
4813
|
+
const originBbox = visualElement.measureViewportBox();
|
|
4814
|
+
const element = visualElement.getInstance();
|
|
4815
|
+
const elementComputedStyle = getComputedStyle(element);
|
|
4816
|
+
const { display } = elementComputedStyle;
|
|
4817
|
+
const origin = {};
|
|
4958
4818
|
// If the element is currently set to display: "none", make it visible before
|
|
4959
4819
|
// measuring the target bounding box
|
|
4960
4820
|
if (display === "none") {
|
|
@@ -4963,50 +4823,48 @@
|
|
|
4963
4823
|
/**
|
|
4964
4824
|
* Record origins before we render and update styles
|
|
4965
4825
|
*/
|
|
4966
|
-
changedKeys.forEach(
|
|
4826
|
+
changedKeys.forEach((key) => {
|
|
4967
4827
|
origin[key] = positionalValues[key](originBbox, elementComputedStyle);
|
|
4968
4828
|
});
|
|
4969
4829
|
// Apply the latest values (as set in checkAndConvertChangedValueTypes)
|
|
4970
4830
|
visualElement.syncRender();
|
|
4971
|
-
|
|
4972
|
-
changedKeys.forEach(
|
|
4831
|
+
const targetBbox = visualElement.measureViewportBox();
|
|
4832
|
+
changedKeys.forEach((key) => {
|
|
4973
4833
|
// Restore styles to their **calculated computed style**, not their actual
|
|
4974
4834
|
// originally set style. This allows us to animate between equivalent pixel units.
|
|
4975
|
-
|
|
4835
|
+
const value = visualElement.getValue(key);
|
|
4976
4836
|
setAndResetVelocity(value, origin[key]);
|
|
4977
4837
|
target[key] = positionalValues[key](targetBbox, elementComputedStyle);
|
|
4978
4838
|
});
|
|
4979
4839
|
return target;
|
|
4980
4840
|
};
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
transitionEnd = __assign({}, transitionEnd);
|
|
4986
|
-
var targetPositionalKeys = Object.keys(target).filter(isPositionalKey);
|
|
4841
|
+
const checkAndConvertChangedValueTypes = (visualElement, target, origin = {}, transitionEnd = {}) => {
|
|
4842
|
+
target = Object.assign({}, target);
|
|
4843
|
+
transitionEnd = Object.assign({}, transitionEnd);
|
|
4844
|
+
const targetPositionalKeys = Object.keys(target).filter(isPositionalKey);
|
|
4987
4845
|
// We want to remove any transform values that could affect the element's bounding box before
|
|
4988
4846
|
// it's measured. We'll reapply these later.
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
targetPositionalKeys.forEach(
|
|
4993
|
-
|
|
4847
|
+
let removedTransformValues = [];
|
|
4848
|
+
let hasAttemptedToRemoveTransformValues = false;
|
|
4849
|
+
const changedValueTypeKeys = [];
|
|
4850
|
+
targetPositionalKeys.forEach((key) => {
|
|
4851
|
+
const value = visualElement.getValue(key);
|
|
4994
4852
|
if (!visualElement.hasValue(key))
|
|
4995
4853
|
return;
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
4854
|
+
let from = origin[key];
|
|
4855
|
+
let fromType = findDimensionValueType(from);
|
|
4856
|
+
const to = target[key];
|
|
4857
|
+
let toType;
|
|
5000
4858
|
// TODO: The current implementation of this basically throws an error
|
|
5001
4859
|
// if you try and do value conversion via keyframes. There's probably
|
|
5002
4860
|
// a way of doing this but the performance implications would need greater scrutiny,
|
|
5003
4861
|
// as it'd be doing multiple resize-remeasure operations.
|
|
5004
4862
|
if (isKeyframesTarget(to)) {
|
|
5005
|
-
|
|
5006
|
-
|
|
4863
|
+
const numKeyframes = to.length;
|
|
4864
|
+
const fromIndex = to[0] === null ? 1 : 0;
|
|
5007
4865
|
from = to[fromIndex];
|
|
5008
4866
|
fromType = findDimensionValueType(from);
|
|
5009
|
-
for (
|
|
4867
|
+
for (let i = fromIndex; i < numKeyframes; i++) {
|
|
5010
4868
|
if (!toType) {
|
|
5011
4869
|
toType = findDimensionValueType(to[i]);
|
|
5012
4870
|
invariant(toType === fromType ||
|
|
@@ -5024,7 +4882,7 @@
|
|
|
5024
4882
|
// If they're both just number or px, convert them both to numbers rather than
|
|
5025
4883
|
// relying on resize/remeasure to convert (which is wasteful in this situation)
|
|
5026
4884
|
if (isNumOrPxType(fromType) && isNumOrPxType(toType)) {
|
|
5027
|
-
|
|
4885
|
+
const current = value.get();
|
|
5028
4886
|
if (typeof current === "string") {
|
|
5029
4887
|
value.set(parseFloat(current));
|
|
5030
4888
|
}
|
|
@@ -5065,26 +4923,26 @@
|
|
|
5065
4923
|
}
|
|
5066
4924
|
});
|
|
5067
4925
|
if (changedValueTypeKeys.length) {
|
|
5068
|
-
|
|
4926
|
+
const scrollY = changedValueTypeKeys.indexOf("height") >= 0
|
|
5069
4927
|
? window.pageYOffset
|
|
5070
4928
|
: null;
|
|
5071
|
-
|
|
4929
|
+
const convertedTarget = convertChangedValueTypes(target, visualElement, changedValueTypeKeys);
|
|
5072
4930
|
// If we removed transform values, reapply them before the next render
|
|
5073
4931
|
if (removedTransformValues.length) {
|
|
5074
|
-
removedTransformValues.forEach(
|
|
5075
|
-
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
4932
|
+
removedTransformValues.forEach(([key, value]) => {
|
|
5076
4933
|
visualElement.getValue(key).set(value);
|
|
5077
4934
|
});
|
|
5078
4935
|
}
|
|
5079
4936
|
// Reapply original values
|
|
5080
4937
|
visualElement.syncRender();
|
|
5081
4938
|
// Restore scroll position
|
|
5082
|
-
if (
|
|
5083
|
-
window.scrollTo({ top:
|
|
5084
|
-
|
|
4939
|
+
if (isBrowser && scrollY !== null) {
|
|
4940
|
+
window.scrollTo({ top: scrollY });
|
|
4941
|
+
}
|
|
4942
|
+
return { target: convertedTarget, transitionEnd };
|
|
5085
4943
|
}
|
|
5086
4944
|
else {
|
|
5087
|
-
return { target
|
|
4945
|
+
return { target, transitionEnd };
|
|
5088
4946
|
}
|
|
5089
4947
|
};
|
|
5090
4948
|
/**
|
|
@@ -5097,22 +4955,21 @@
|
|
|
5097
4955
|
function unitConversion(visualElement, target, origin, transitionEnd) {
|
|
5098
4956
|
return hasPositionalKey(target)
|
|
5099
4957
|
? checkAndConvertChangedValueTypes(visualElement, target, origin, transitionEnd)
|
|
5100
|
-
: { target
|
|
4958
|
+
: { target, transitionEnd };
|
|
5101
4959
|
}
|
|
5102
4960
|
|
|
5103
4961
|
/**
|
|
5104
4962
|
* Parse a DOM variant to make it animatable. This involves resolving CSS variables
|
|
5105
4963
|
* and ensuring animations like "20%" => "calc(50vw)" are performed in pixels.
|
|
5106
4964
|
*/
|
|
5107
|
-
|
|
5108
|
-
|
|
4965
|
+
const parseDomVariant = (visualElement, target, origin, transitionEnd) => {
|
|
4966
|
+
const resolved = resolveCSSVariables(visualElement, target, transitionEnd);
|
|
5109
4967
|
target = resolved.target;
|
|
5110
4968
|
transitionEnd = resolved.transitionEnd;
|
|
5111
4969
|
return unitConversion(visualElement, target, origin, transitionEnd);
|
|
5112
4970
|
};
|
|
5113
4971
|
|
|
5114
|
-
function isForcedMotionValue(key,
|
|
5115
|
-
var layout = _a.layout, layoutId = _a.layoutId;
|
|
4972
|
+
function isForcedMotionValue(key, { layout, layoutId }) {
|
|
5116
4973
|
return (isTransformProp(key) ||
|
|
5117
4974
|
isTransformOriginProp(key) ||
|
|
5118
4975
|
((layout || layoutId !== undefined) &&
|
|
@@ -5120,9 +4977,9 @@
|
|
|
5120
4977
|
}
|
|
5121
4978
|
|
|
5122
4979
|
function scrapeMotionValuesFromProps(props) {
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
for (
|
|
4980
|
+
const { style } = props;
|
|
4981
|
+
const newValues = {};
|
|
4982
|
+
for (const key in style) {
|
|
5126
4983
|
if (isMotionValue(style[key]) || isForcedMotionValue(key, props)) {
|
|
5127
4984
|
newValues[key] = style[key];
|
|
5128
4985
|
}
|
|
@@ -5130,11 +4987,10 @@
|
|
|
5130
4987
|
return newValues;
|
|
5131
4988
|
}
|
|
5132
4989
|
|
|
5133
|
-
function renderHTML(element,
|
|
5134
|
-
var style = _a.style, vars = _a.vars;
|
|
4990
|
+
function renderHTML(element, { style, vars }, styleProp, projection) {
|
|
5135
4991
|
Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
|
|
5136
4992
|
// Loop over any CSS variables and assign those.
|
|
5137
|
-
for (
|
|
4993
|
+
for (const key in vars) {
|
|
5138
4994
|
element.style.setProperty(key, vars[key]);
|
|
5139
4995
|
}
|
|
5140
4996
|
}
|
|
@@ -5144,8 +5000,7 @@
|
|
|
5144
5000
|
* it's easier to consider each axis individually. This function returns a bounding box
|
|
5145
5001
|
* as a map of single-axis min/max values.
|
|
5146
5002
|
*/
|
|
5147
|
-
function convertBoundingBoxToBox(
|
|
5148
|
-
var top = _a.top, left = _a.left, right = _a.right, bottom = _a.bottom;
|
|
5003
|
+
function convertBoundingBoxToBox({ top, left, right, bottom, }) {
|
|
5149
5004
|
return {
|
|
5150
5005
|
x: { min: left, max: right },
|
|
5151
5006
|
y: { min: top, max: bottom },
|
|
@@ -5159,8 +5014,8 @@
|
|
|
5159
5014
|
function transformBoxPoints(point, transformPoint) {
|
|
5160
5015
|
if (!transformPoint)
|
|
5161
5016
|
return point;
|
|
5162
|
-
|
|
5163
|
-
|
|
5017
|
+
const topLeft = transformPoint({ x: point.left, y: point.top });
|
|
5018
|
+
const bottomRight = transformPoint({ x: point.right, y: point.bottom });
|
|
5164
5019
|
return {
|
|
5165
5020
|
top: topLeft.y,
|
|
5166
5021
|
left: topLeft.x,
|
|
@@ -5176,22 +5031,22 @@
|
|
|
5176
5031
|
function getComputedStyle$1(element) {
|
|
5177
5032
|
return window.getComputedStyle(element);
|
|
5178
5033
|
}
|
|
5179
|
-
|
|
5034
|
+
const htmlConfig = {
|
|
5180
5035
|
treeType: "dom",
|
|
5181
|
-
readValueFromInstance
|
|
5036
|
+
readValueFromInstance(domElement, key) {
|
|
5182
5037
|
if (isTransformProp(key)) {
|
|
5183
|
-
|
|
5038
|
+
const defaultType = getDefaultValueType(key);
|
|
5184
5039
|
return defaultType ? defaultType.default || 0 : 0;
|
|
5185
5040
|
}
|
|
5186
5041
|
else {
|
|
5187
|
-
|
|
5188
|
-
|
|
5042
|
+
const computedStyle = getComputedStyle$1(domElement);
|
|
5043
|
+
const value = (isCSSVariable(key)
|
|
5189
5044
|
? computedStyle.getPropertyValue(key)
|
|
5190
5045
|
: computedStyle[key]) || 0;
|
|
5191
5046
|
return typeof value === "string" ? value.trim() : value;
|
|
5192
5047
|
}
|
|
5193
5048
|
},
|
|
5194
|
-
sortNodePosition
|
|
5049
|
+
sortNodePosition(a, b) {
|
|
5195
5050
|
/**
|
|
5196
5051
|
* compareDocumentPosition returns a bitmask, by using the bitwise &
|
|
5197
5052
|
* we're returning true if 2 in that bitmask is set to true. 2 is set
|
|
@@ -5199,12 +5054,11 @@
|
|
|
5199
5054
|
*/
|
|
5200
5055
|
return a.compareDocumentPosition(b) & 2 ? 1 : -1;
|
|
5201
5056
|
},
|
|
5202
|
-
getBaseTarget
|
|
5057
|
+
getBaseTarget(props, key) {
|
|
5203
5058
|
var _a;
|
|
5204
5059
|
return (_a = props.style) === null || _a === void 0 ? void 0 : _a[key];
|
|
5205
5060
|
},
|
|
5206
|
-
measureViewportBox
|
|
5207
|
-
var transformPagePoint = _a.transformPagePoint;
|
|
5061
|
+
measureViewportBox(element, { transformPagePoint }) {
|
|
5208
5062
|
return measureViewportBox(element, transformPagePoint);
|
|
5209
5063
|
},
|
|
5210
5064
|
/**
|
|
@@ -5214,19 +5068,18 @@
|
|
|
5214
5068
|
* layout transforms up the tree in the same way this.getBoundingBoxWithoutTransforms
|
|
5215
5069
|
* works
|
|
5216
5070
|
*/
|
|
5217
|
-
resetTransform
|
|
5218
|
-
|
|
5071
|
+
resetTransform(element, domElement, props) {
|
|
5072
|
+
const { transformTemplate } = props;
|
|
5219
5073
|
domElement.style.transform = transformTemplate
|
|
5220
5074
|
? transformTemplate({}, "")
|
|
5221
5075
|
: "none";
|
|
5222
5076
|
// Ensure that whatever happens next, we restore our transform on the next frame
|
|
5223
5077
|
element.scheduleRender();
|
|
5224
5078
|
},
|
|
5225
|
-
restoreTransform
|
|
5079
|
+
restoreTransform(instance, mutableState) {
|
|
5226
5080
|
instance.style.transform = mutableState.style.transform;
|
|
5227
5081
|
},
|
|
5228
|
-
removeValueFromRenderState
|
|
5229
|
-
var vars = _a.vars, style = _a.style;
|
|
5082
|
+
removeValueFromRenderState(key, { vars, style }) {
|
|
5230
5083
|
delete vars[key];
|
|
5231
5084
|
delete style[key];
|
|
5232
5085
|
},
|
|
@@ -5234,11 +5087,11 @@
|
|
|
5234
5087
|
* Ensure that HTML and Framer-specific value types like `px`->`%` and `Color`
|
|
5235
5088
|
* can be animated by Motion.
|
|
5236
5089
|
*/
|
|
5237
|
-
makeTargetAnimatable
|
|
5238
|
-
var
|
|
5090
|
+
makeTargetAnimatable(element, _a, _b, isMounted) {
|
|
5091
|
+
var { transition, transitionEnd } = _a, target = __rest(_a, ["transition", "transitionEnd"]);
|
|
5239
5092
|
var transformValues = _b.transformValues;
|
|
5240
5093
|
if (isMounted === void 0) { isMounted = true; }
|
|
5241
|
-
|
|
5094
|
+
let origin = getOrigin(target, transition || {}, element);
|
|
5242
5095
|
/**
|
|
5243
5096
|
* If Framer has provided a function to convert `Color` etc value types, convert them
|
|
5244
5097
|
*/
|
|
@@ -5252,14 +5105,15 @@
|
|
|
5252
5105
|
}
|
|
5253
5106
|
if (isMounted) {
|
|
5254
5107
|
checkTargetForNewValues(element, target, origin);
|
|
5255
|
-
|
|
5108
|
+
const parsed = parseDomVariant(element, target, origin, transitionEnd);
|
|
5256
5109
|
transitionEnd = parsed.transitionEnd;
|
|
5257
5110
|
target = parsed.target;
|
|
5258
5111
|
}
|
|
5259
|
-
return
|
|
5112
|
+
return Object.assign({ transition,
|
|
5113
|
+
transitionEnd }, target);
|
|
5260
5114
|
},
|
|
5261
|
-
scrapeMotionValuesFromProps
|
|
5262
|
-
build
|
|
5115
|
+
scrapeMotionValuesFromProps,
|
|
5116
|
+
build(element, renderState, latestValues, options, props) {
|
|
5263
5117
|
if (element.isVisible !== undefined) {
|
|
5264
5118
|
renderState.style.visibility = element.isVisible
|
|
5265
5119
|
? "visible"
|
|
@@ -5269,7 +5123,7 @@
|
|
|
5269
5123
|
},
|
|
5270
5124
|
render: renderHTML,
|
|
5271
5125
|
};
|
|
5272
|
-
|
|
5126
|
+
const htmlVisualElement = visualElement(htmlConfig);
|
|
5273
5127
|
|
|
5274
5128
|
exports.HTMLProjectionNode = HTMLProjectionNode;
|
|
5275
5129
|
exports.addScaleCorrector = addScaleCorrector;
|