@react-hive/honey-utils 3.17.0 → 3.18.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/README.md +1 -1
- package/dist/README.md +1 -1
- package/dist/geometry/apply-inertia-step.d.ts +68 -81
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.dev.cjs +31 -59
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.dev.cjs
CHANGED
|
@@ -1631,75 +1631,47 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
1631
1631
|
/* harmony import */ var _geometry__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ~/geometry */ "./src/geometry/index.ts");
|
|
1632
1632
|
|
|
1633
1633
|
/**
|
|
1634
|
-
* Advances a value by
|
|
1634
|
+
* Advances a value by a single inertial step using velocity,
|
|
1635
|
+
* elapsed time, exponential friction, and hard bounds.
|
|
1635
1636
|
*
|
|
1636
|
-
* This
|
|
1637
|
-
* {@link resolveBoundedDelta}, which
|
|
1637
|
+
* This function models **momentum-driven motion** and delegates
|
|
1638
|
+
* boundary enforcement to {@link resolveBoundedDelta}, which guarantees:
|
|
1639
|
+
* - no overshoot
|
|
1640
|
+
* - no jitter at bounds
|
|
1641
|
+
* - deterministic stopping behavior
|
|
1638
1642
|
*
|
|
1639
|
-
*
|
|
1640
|
-
* - Integrates velocity over the elapsed time to produce a movement delta
|
|
1641
|
-
* - Resolves that delta against fixed bounds
|
|
1642
|
-
* - Applies exponential friction to gradually reduce velocity
|
|
1643
|
-
* - Stops immediately when a bound is hit or velocity falls below a threshold
|
|
1643
|
+
* ---
|
|
1644
1644
|
*
|
|
1645
|
-
*
|
|
1646
|
-
*
|
|
1645
|
+
* ### Termination conditions
|
|
1646
|
+
* Inertia stops immediately when:
|
|
1647
|
+
* - the absolute velocity falls below `minVelocityPxMs`, or
|
|
1648
|
+
* - movement in the current direction is blocked by a bound
|
|
1649
|
+
*
|
|
1650
|
+
* ---
|
|
1651
|
+
*
|
|
1652
|
+
* ⚠️ **Single-step function**
|
|
1653
|
+
* This function performs **one inertia step only**.
|
|
1654
|
+
* It must be called repeatedly from an animation loop
|
|
1655
|
+
* (e.g. `requestAnimationFrame`) to produce continuous motion.
|
|
1656
|
+
*
|
|
1657
|
+
* ---
|
|
1647
1658
|
*
|
|
1648
1659
|
* ### Common use cases
|
|
1649
1660
|
* - Synthetic scrolling with momentum
|
|
1661
|
+
* - Drag-to-scroll interactions
|
|
1650
1662
|
* - Carousels and sliders
|
|
1651
1663
|
* - Timelines and scrubbers
|
|
1652
|
-
* - Drag-to-scroll interactions with inertia
|
|
1653
|
-
*
|
|
1654
|
-
* @param value - Current value before applying inertia (e.g. translate position).
|
|
1655
|
-
* @param min - Minimum allowed value (inclusive).
|
|
1656
|
-
* @param max - Maximum allowed value (inclusive).
|
|
1657
|
-
* @param velocity - Current velocity in units per millisecond (e.g. px/ms).
|
|
1658
|
-
* @param deltaTime - Time elapsed since the previous step, in milliseconds.
|
|
1659
|
-
* @param friction - Exponential friction coefficient controlling decay rate.
|
|
1660
|
-
* @param minVelocity - Minimum velocity below which inertia stops.
|
|
1661
|
-
*
|
|
1662
|
-
* @returns An object containing the updated value and velocity,
|
|
1663
|
-
* or `null` when inertia has completed or movement is no longer possible.
|
|
1664
|
-
*
|
|
1665
|
-
* @example
|
|
1666
|
-
* ```ts
|
|
1667
|
-
* let value = translateX;
|
|
1668
|
-
* let velocity = releaseVelocity; // px/ms from drag end
|
|
1669
|
-
* let lastTime = performance.now();
|
|
1670
|
-
*
|
|
1671
|
-
* const step = (time: number) => {
|
|
1672
|
-
* const deltaTime = time - lastTime;
|
|
1673
|
-
* lastTime = time;
|
|
1674
|
-
*
|
|
1675
|
-
* const result = applyInertiaStep({
|
|
1676
|
-
* value,
|
|
1677
|
-
* velocity,
|
|
1678
|
-
* min: -maxOverflow,
|
|
1679
|
-
* max: 0,
|
|
1680
|
-
* deltaTime,
|
|
1681
|
-
* });
|
|
1682
|
-
*
|
|
1683
|
-
* if (!result) {
|
|
1684
|
-
* return; // inertia finished
|
|
1685
|
-
* }
|
|
1686
|
-
*
|
|
1687
|
-
* value = result.value;
|
|
1688
|
-
* velocity = result.velocity;
|
|
1689
1664
|
*
|
|
1690
|
-
*
|
|
1691
|
-
*
|
|
1692
|
-
*
|
|
1693
|
-
*
|
|
1694
|
-
* requestAnimationFrame(step);
|
|
1695
|
-
* ```
|
|
1665
|
+
* @returns An {@link InertiaStepResult} when inertia is still active,
|
|
1666
|
+
* or `null` when inertia has completed or further movement
|
|
1667
|
+
* is not possible.
|
|
1696
1668
|
*/
|
|
1697
|
-
const applyInertiaStep = ({ value, min, max,
|
|
1698
|
-
if (Math.abs(
|
|
1669
|
+
const applyInertiaStep = ({ value, min, max, velocityPxMs, deltaTimeMs, friction = 0.002, minVelocityPxMs = 0.01, }) => {
|
|
1670
|
+
if (Math.abs(velocityPxMs) < minVelocityPxMs) {
|
|
1699
1671
|
return null;
|
|
1700
1672
|
}
|
|
1701
1673
|
// Distance we want to move this frame
|
|
1702
|
-
const delta =
|
|
1674
|
+
const delta = velocityPxMs * deltaTimeMs;
|
|
1703
1675
|
const nextValue = (0,_geometry__WEBPACK_IMPORTED_MODULE_0__.resolveBoundedDelta)({
|
|
1704
1676
|
delta,
|
|
1705
1677
|
value,
|
|
@@ -1711,11 +1683,11 @@ const applyInertiaStep = ({ value, min, max, velocity, deltaTime, friction = 0.0
|
|
|
1711
1683
|
return null;
|
|
1712
1684
|
}
|
|
1713
1685
|
// Apply exponential friction
|
|
1714
|
-
const decay = Math.exp(-friction *
|
|
1715
|
-
const
|
|
1686
|
+
const decay = Math.exp(-friction * deltaTimeMs);
|
|
1687
|
+
const nextVelocityPxMs = velocityPxMs * decay;
|
|
1716
1688
|
return {
|
|
1717
1689
|
value: nextValue,
|
|
1718
|
-
|
|
1690
|
+
velocityPxMs: nextVelocityPxMs,
|
|
1719
1691
|
};
|
|
1720
1692
|
};
|
|
1721
1693
|
|