motion-dom 12.32.0 → 12.34.0-alpha.0

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 CHANGED
@@ -146,7 +146,7 @@ function createRenderBatcher(scheduleNextBatch, allowKeepAlive) {
146
146
  render.process(state);
147
147
  postRender.process(state);
148
148
  state.isProcessing = false;
149
- if (runNextFrame && allowKeepAlive) {
149
+ if (runNextFrame && allowKeepAlive && !motionUtils.MotionGlobalConfig.useManualTiming) {
150
150
  useDefaultElapsed = false;
151
151
  scheduleNextBatch(processBatch);
152
152
  }
@@ -154,10 +154,32 @@ function createRenderBatcher(scheduleNextBatch, allowKeepAlive) {
154
154
  const wake = () => {
155
155
  runNextFrame = true;
156
156
  useDefaultElapsed = true;
157
- if (!state.isProcessing) {
157
+ if (!state.isProcessing &&
158
+ (!motionUtils.MotionGlobalConfig.useManualTiming || !allowKeepAlive)) {
158
159
  scheduleNextBatch(processBatch);
159
160
  }
160
161
  };
162
+ /**
163
+ * Manually process all scheduled frame callbacks.
164
+ * Used for manual frame rendering in environments without requestAnimationFrame
165
+ * (e.g., WebXR, Remotion, server-side rendering of videos).
166
+ */
167
+ const processFrame = (timestamp, delta) => {
168
+ runNextFrame = false;
169
+ state.delta = delta !== undefined ? delta : 1000 / 60;
170
+ state.timestamp = timestamp;
171
+ state.isProcessing = true;
172
+ // Unrolled render loop for better per-frame performance
173
+ setup.process(state);
174
+ read.process(state);
175
+ resolveKeyframes.process(state);
176
+ preUpdate.process(state);
177
+ update.process(state);
178
+ preRender.process(state);
179
+ render.process(state);
180
+ postRender.process(state);
181
+ state.isProcessing = false;
182
+ };
161
183
  const schedule = stepsOrder.reduce((acc, key) => {
162
184
  const step = steps[key];
163
185
  acc[key] = (process, keepAlive = false, immediate = false) => {
@@ -172,10 +194,10 @@ function createRenderBatcher(scheduleNextBatch, allowKeepAlive) {
172
194
  steps[stepsOrder[i]].cancel(process);
173
195
  }
174
196
  };
175
- return { schedule, cancel, state, steps };
197
+ return { schedule, cancel, state, steps, processFrame };
176
198
  }
177
199
 
178
- const { schedule: frame, cancel: cancelFrame, state: frameData, steps: frameSteps, } = /* @__PURE__ */ createRenderBatcher(typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : motionUtils.noop, true);
200
+ const { schedule: frame, cancel: cancelFrame, state: frameData, steps: frameSteps, processFrame, } = /* @__PURE__ */ createRenderBatcher(typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : motionUtils.noop, true);
179
201
 
180
202
  let now;
181
203
  function clearTime() {
@@ -192,7 +214,8 @@ function clearTime() {
192
214
  const time = {
193
215
  now: () => {
194
216
  if (now === undefined) {
195
- time.set(frameData.isProcessing || motionUtils.MotionGlobalConfig.useManualTiming
217
+ time.set(frameData.isProcessing ||
218
+ motionUtils.MotionGlobalConfig.useManualTiming
196
219
  ? frameData.timestamp
197
220
  : performance.now());
198
221
  }
@@ -702,6 +725,48 @@ function mix(from, to, p) {
702
725
  return mixer(from, to);
703
726
  }
704
727
 
728
+ /**
729
+ * Manually render a single animation frame.
730
+ *
731
+ * Temporarily enables `useManualTiming` mode during frame processing
732
+ * to prevent requestAnimationFrame from auto-advancing animations.
733
+ *
734
+ * @example
735
+ * renderFrame({ timestamp: 1000 }) // Render at 1 second
736
+ *
737
+ * @example
738
+ * // Using frame number
739
+ * renderFrame({ frame: 30, fps: 30 }) // Render at frame 30 (1 second at 30fps)
740
+ */
741
+ function renderFrame(options = {}) {
742
+ const { timestamp, frame, fps = 30, delta } = options;
743
+ let frameTimestamp;
744
+ let frameDelta;
745
+ if (timestamp !== undefined) {
746
+ frameTimestamp = timestamp;
747
+ frameDelta = delta !== undefined ? delta : 1000 / 60;
748
+ }
749
+ else if (frame !== undefined) {
750
+ // Convert frame number to milliseconds
751
+ frameTimestamp = (frame / fps) * 1000;
752
+ frameDelta = delta !== undefined ? delta : 1000 / fps;
753
+ }
754
+ else {
755
+ // Use current frameData timestamp + default delta if no timing info provided
756
+ frameDelta = delta !== undefined ? delta : 1000 / 60;
757
+ frameTimestamp = frameData.timestamp + frameDelta;
758
+ }
759
+ // Temporarily enable manual timing mode during frame processing
760
+ const previousManualTiming = motionUtils.MotionGlobalConfig.useManualTiming;
761
+ motionUtils.MotionGlobalConfig.useManualTiming = true;
762
+ // Set the synchronized time
763
+ time.set(frameTimestamp);
764
+ // Process the frame - this runs all registered callbacks
765
+ processFrame(frameTimestamp, frameDelta);
766
+ // Restore previous manual timing setting
767
+ motionUtils.MotionGlobalConfig.useManualTiming = previousManualTiming;
768
+ }
769
+
705
770
  const frameloopDriver = (update) => {
706
771
  const passTimestamp = ({ timestamp }) => update(timestamp);
707
772
  return {
@@ -1426,7 +1491,12 @@ class JSAnimation extends WithPromise {
1426
1491
  this.currentTime = Math.max(timeWithoutDelay, 0);
1427
1492
  // If this animation has finished, set the current time to the total duration.
1428
1493
  if (this.state === "finished" && this.holdTime === null) {
1429
- this.currentTime = totalDuration;
1494
+ if (motionUtils.MotionGlobalConfig.useManualTiming && this.currentTime < totalDuration) {
1495
+ this.state = "running";
1496
+ }
1497
+ else {
1498
+ this.currentTime = totalDuration;
1499
+ }
1430
1500
  }
1431
1501
  let elapsed = this.currentTime;
1432
1502
  let frameGenerator = generator;
@@ -1550,7 +1620,8 @@ class JSAnimation extends WithPromise {
1550
1620
  play() {
1551
1621
  if (this.isStopped)
1552
1622
  return;
1553
- const { driver = frameloopDriver, startTime } = this.options;
1623
+ const { startTime } = this.options;
1624
+ const driver = this.options.driver ?? frameloopDriver;
1554
1625
  if (!this.driver) {
1555
1626
  this.driver = driver((timestamp) => this.tick(timestamp));
1556
1627
  }
@@ -1591,7 +1662,9 @@ class JSAnimation extends WithPromise {
1591
1662
  }
1592
1663
  finish() {
1593
1664
  this.notifyFinished();
1594
- this.teardown();
1665
+ if (!motionUtils.MotionGlobalConfig.useManualTiming) {
1666
+ this.teardown();
1667
+ }
1595
1668
  this.state = "finished";
1596
1669
  this.options.onComplete?.();
1597
1670
  }
@@ -2371,7 +2444,8 @@ function supportsBrowserAnimation(options) {
2371
2444
  return false;
2372
2445
  }
2373
2446
  const { onUpdate, transformTemplate } = motionValue.owner.getProps();
2374
- return (supportsWaapi() &&
2447
+ return (!motionUtils.MotionGlobalConfig.useManualTiming &&
2448
+ supportsWaapi() &&
2375
2449
  name &&
2376
2450
  acceleratedValues$1.has(name) &&
2377
2451
  (name !== "transform" || !transformTemplate) &&
@@ -4415,6 +4489,7 @@ const enableKeyboardPress = (focusEvent, eventOptions) => {
4415
4489
  function isValidPressEvent(event) {
4416
4490
  return isPrimaryPointer(event) && !isDragActive();
4417
4491
  }
4492
+ const claimedPointerDownEvents = new WeakSet();
4418
4493
  /**
4419
4494
  * Create a press gesture.
4420
4495
  *
@@ -4440,7 +4515,12 @@ function press(targetOrSelector, onPressStart, options = {}) {
4440
4515
  const target = startEvent.currentTarget;
4441
4516
  if (!isValidPressEvent(startEvent))
4442
4517
  return;
4518
+ if (claimedPointerDownEvents.has(startEvent))
4519
+ return;
4443
4520
  isPressing.add(target);
4521
+ if (options.stopPropagation) {
4522
+ claimedPointerDownEvents.add(startEvent);
4523
+ }
4444
4524
  const onPressEnd = onPressStart(target, startEvent);
4445
4525
  const onPointerEnd = (endEvent, success) => {
4446
4526
  window.removeEventListener("pointerup", onPointerUp);
@@ -6822,6 +6902,22 @@ function createAnimationState(visualElement) {
6822
6902
  typeof prop === "boolean") {
6823
6903
  continue;
6824
6904
  }
6905
+ /**
6906
+ * If exit is already active and wasn't just activated, skip
6907
+ * re-processing to prevent interrupting running exit animations.
6908
+ * Re-resolving exit with a changed custom value can start new
6909
+ * value animations that stop the originals, leaving the exit
6910
+ * animation promise unresolved and the component stuck in the DOM.
6911
+ */
6912
+ if (type === "exit" && typeState.isActive && activeDelta !== true) {
6913
+ if (typeState.prevResolvedValues) {
6914
+ encounteredKeys = {
6915
+ ...encounteredKeys,
6916
+ ...typeState.prevResolvedValues,
6917
+ };
6918
+ }
6919
+ continue;
6920
+ }
6825
6921
  /**
6826
6922
  * As we go look through the values defined on this type, if we detect
6827
6923
  * a changed value or a value that was removed in a higher priority, we set
@@ -9644,6 +9740,7 @@ exports.pixelsToPercent = pixelsToPercent;
9644
9740
  exports.positionalKeys = positionalKeys;
9645
9741
  exports.prefersReducedMotion = prefersReducedMotion;
9646
9742
  exports.press = press;
9743
+ exports.processFrame = processFrame;
9647
9744
  exports.progressPercentage = progressPercentage;
9648
9745
  exports.propEffect = propEffect;
9649
9746
  exports.propagateDirtyNodes = propagateDirtyNodes;
@@ -9654,6 +9751,7 @@ exports.removeAxisDelta = removeAxisDelta;
9654
9751
  exports.removeAxisTransforms = removeAxisTransforms;
9655
9752
  exports.removeBoxTransforms = removeBoxTransforms;
9656
9753
  exports.removePointDelta = removePointDelta;
9754
+ exports.renderFrame = renderFrame;
9657
9755
  exports.renderHTML = renderHTML;
9658
9756
  exports.renderSVG = renderSVG;
9659
9757
  exports.resize = resize;